This question already has answers here:
Objective-C, interface declarations with properties
(4个答案)
6年前关闭。
这是两种标题的区别吗?
(4个答案)
6年前关闭。
这是两种标题的区别吗?
@interface MyObject: NSObject{
NSString *title;
}
@property (nonatomic, retain) NSString *title;
最佳答案
第一个是实例变量。
第二个是财产。
在类的声明(接口)中,大部分不赞成使用实例变量,但是可以在扩展名或@implementation中声明该类内部使用的实例变量。
属性声明API(设置程序/获取程序)和所使用的内存管理模型。默认情况下,现代的编译器将自动合成实例变量以支持属性。