为什么在@interface中声明Object当在Xcode 4中使用@property时

时间:2011-04-06 19:46:42

标签: iphone objective-c properties

@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声明为实例变量是否正确?

2 个答案:

答案 0 :(得分:3)

在现代运行时(具有合理的xcode,模拟器等版本),它没有任何区别,因为编译器会为你生成它。

请注意,使用最新版本的LLVM,您甚至不需要合成;)

答案 1 :(得分:0)

如果您正在使用LLVM编译器,则声明属性声明的实例变量是可选的,因为编译器会自动创建