@interface first : <NSObject> {
NSString *myStr;
/**
I don't understand why declared this NSString *myStr.
Even if not declare NSString *myStr, this codes work well.
**/
}
@property (nonatomic, retain) NSString *myStr;
and Add @synthesize to first.m
如果我总是使用myStr属性,即self.myStr,我不需要将myStr声明为实例变量是否正确?
答案 0 :(得分:3)
在现代运行时(具有合理的xcode,模拟器等版本),它没有任何区别,因为编译器会为你生成它。
请注意,使用最新版本的LLVM,您甚至不需要合成;)
答案 1 :(得分:0)
如果您正在使用LLVM编译器,则声明属性声明的实例变量是可选的,因为编译器会自动创建