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> |
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 实例变量合成访问器方法。
如果不明确的指明私有变量的名称的话,系统就会认为你的私有变量名和属性名是一样的!
本文解析了Objective-C中属性声明及合成的具体用法,解释了@synthesize指令如何为属性生成存取方法,并说明了在不同位宽环境下编译器处理ivar的方式。
241

被折叠的 条评论
为什么被折叠?



