使用obj-c中的属性,我们是否需要声明实例变量?使用obj-c中的属性,我们是否需要声明实例变量?
例如,如果我的.h文件看起来像这样:
@interface MyClass : NSObject {
}
@property (nonatomic, retain) NSNumber *someId;
@property (nonatomic, retain) NSDate *expires;
@property (nonatomic, retain) NSString *someString;
...
是罚款?它编译和工作,是'做过的事'吗?或者我应该真的做到以下几点:
@interface MyClass : NSObject {
NSNumber *someId;
NSDate *expires;
NSString *someString;
}
@property (nonatomic, retain) NSNumber *someId;
@property (nonatomic, retain) NSDate *expires;
@property (nonatomic, retain) NSString *someString;
...
如果我打算总是使用属性访问器,上述两种方法是否有区别?
@synthesize是否照顾为我创建实例变量?
请[发布之前搜索(HTTP://计算器.com/search?q =%5Bobjc%5D + property + declare + ivar)[1](http://stackoverflow.com/questions/5031230/)[2](http://stackoverflow.com/questions/3336922 /)[3](http://stackoverflow.com/questions/4299487/)[4](http://stackoverflow.com/questions/4333797/)[5](http://stackoverflow.com/questions/ 4706816 /) – 2011-05-03 02:38:16