可能的重复:
Objective-C 2.0 中的属性和实例变量
我对这两个代码段感到困惑:
First:
//.h
@interface Student : NSObject {
}
@property (nonautomic, copy) NSString *name;
@property (nonautomic, retain) NSNumber *age;
@end
//.m
@implementation Student
@synthesize name;
@synthesize age;
@end
Second:
//.h
@interface Student : NSObject {
NSString *name; // <<============ difference
NSNumber *age; // <<============ difference
}
@property (nonautomic, copy) NSString *name;
@property (nonautomic, retain) NSNumber *age;
@end
//.m
@implementation Student
@synthesize name;
@synthesize age;
@end
这两种方法都可以。那么是否需要在其中声明变量{}
?
从现代运行时(x86_64 和 ARM6...以及 iOS Simulator)开始,您不再需要声明合成的 ivars。在第一个示例中,@synthesize 正在为您添加实例变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)