为什么在@interface中声明对象在Xcode 4中使用@property时 [英] why declare Object in @interface When used @property In Xcode 4

查看:47
本文介绍了为什么在@interface中声明对象在Xcode 4中使用@property时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

在现代运行时(带有合理版本的xcode,模拟器等)中,这没有什么区别,因为编译器会为您生成它.

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

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

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

这篇关于为什么在@interface中声明对象在Xcode 4中使用@property时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆