这里有很多东西可以挑选。首先,几乎所有你声明的类都应该继承自NSObject.
@interface MainClass : NSObject {
您应该使用@propertyand@synthesize创建一个实例变量,不要像您尝试做的那样分配 iVar。最好这样写:
@interface MainClass : NSObject
@property(nonatomic, retain) CustomClass *test1;
@end
@implementation MainClass
@synthesize test1;
// only if you're not using ARC
-(void)dealloc {
[test1 release];
[super dealloc];
}
@end
例如)像 test1.myowner?还是 test1<-self?或 test1/self 等。
所有这些都是错误的,如果您想从 test1 访问 MainClass 的实例,您必须在该类上声明一个实例变量并将“ self”设置为该实例变量。MainClass如果您只拥有一个实例,那么将其实现为单例可能是一个更好的主意。