您的位置:首页 > 移动开发 > IOS开发

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

2012-07-24 13:28 357 查看
1
@synthesizewindow=_window;
2
@synthesizeviewController=_viewController;
通常看到的都没有包含=部分,@synthesize
window=_window;怎么理解?这里的_window和_viewController是什么变量?

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

1
#import<UIKit/UIKit.h><atarget="_blank"rel="nofollow">@class</a>ViewController;<atarget="_blank"rel="nofollow">@interface</a>AppDelegate:NSObject<UIApplicationDelegate>
2
3
@property(nonatomic,retain)IBOutletUIWindow*window;
4
@property(nonatomic,retain)IBOutletViewController*viewController;
5
<atarget=
"_blank"

rel=
"nofollow"
>@end</a>

32-bit时,如果类的@interface部分没有进行ivar声明,但有@property声明,在类的@implementation部分有响应的@synthesize,则会得到类似下面的编译错误:

Synthesized
property'xX'musteitherbenamedthesameasacompatibleivarormustexplicitlynameanivar


64-bit时,运行时系统会自动给类添加ivar,添加的ivar以一个下划线"_"做前缀。

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

如果不明确的指明私有变量的名称的话,系统就会认为你的私有变量名和属性名是一样的!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: