开发者

why declare Object in @interface When used @property In Xcode 4

开发者 https://www.devze.com 2023-02-22 08:25 出处:网络
@interface开发者_开发百科 first : <NSObject> { NSString *myStr; /** I don\'t understand why declared this NSString *myStr.
@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

Is it correct that I don't need to declare myStr as an instance variable if I always use the myStr property, i.e. self.myStr?


In the modern runtime (with a reasonably recent version of xcode, simulator etc.) it makes no difference because the compiler generates it for you.

Note that with the newest version of LLVM you don't even need the synthesize ;)


if you are using LLVM compiler then declaring instance variable who's property is declared is optional as the compiler creates automatically

0

精彩评论

暂无评论...
验证码 换一张
取 消