Usually we have codes like these
@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window;
And also second version
@interface TestAppDelegate开发者_如何学JAVA : NSObject <UIApplicationDelegate> {
UIWindow *_window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window = _window;
Quetions are
- what is the big difference ? Which better ? and Why ?
- For first version, Why what is the default attribute member of window ,which is _window in second version. Does that KVC or KVO work inside ?
in the default instance it is the same as
@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window = window;
which would actually not need an Assignment on the synthesize. and would probably generate an error.
This is the normal way that I do it.
@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@synthesize window;
I explicitly declare the Instance Variable
UIWindow *window;
so that I know it is there, (they are generally all right next to each other.)
and I separate them by the ones I retain and the ones I dont. So that I know to release them in my dealloc method
精彩评论