ios5 编程关于@synthesize window = _window的理解

1@synthesize window=_window;
2@synthesize viewController=_viewController;

通常看到的都没有包含=部分,@synthesize window=_window; 怎么理解?这里的 _window 和 _viewController 是什么变量?

.h 文件中在类中没有定义 window 和 viewController 实例变量,怎么能进行 @perproty 声明呢?

1#import <UIKit/UIKit.h> <a  target="_blank" rel="nofollow">@class</a>  ViewController;<a  target="_blank" rel="nofollow">@interface</a>  AppDelegate : NSObject <UIApplicationDelegate>
2 
3@property (nonatomic, retain) IBOutlet UIWindow *window;
4@property (nonatomic, retain) IBOutlet ViewController *viewController;
5 <a  target="_blank" rel="nofollow">@end</a>
在 32-bit 时,如果类的 @interface 部分没有进行 ivar 声明,但有 @property 声明,在类的 @implementation 部分有响应的 @synthesize,则会得到类似下面的编译错误:  
Synthesized property 'xX' must either be named the same as a compatible ivar or must explicitly name an ivar  
在 64-bit时,运行时系统会自动给类添加 ivar,添加的 ivar 以一个下划线"_"做前缀。  

上面声明部分的 @synthesize window=_window; 意思是说,window 属性为 _window 实例变量合成访问器方法。

如果不明确的指明私有变量的名称的话,系统就会认为你的私有变量名和属性名是一样的!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值