I kind of like the iOS way of开发者_如何学运维 not having to specify ivars, but I dunno wether it's possible to do the same in Cocoa or if it's a bad idea.
Here is the same code in Cocoa and iOS
// Cocoa
@interface Foobar : NSObject {
NSString* m_name;
}
@property (nonatomic, retain) NSString* name;
@end
@implementation Foobar
@synthesize name = m_name;
@end
// iOS
@interface Foobar : NSObject {
// no ivar here
}
@property (nonatomic, retain) NSString* name;
@end
@implementation Foobar
@synthesize name;
@end
The ability to elide ivars requires the “non-fragile” Objective-C runtime. 32-bit versions of Mac OS X use the “fragile” runtime. If you’re targeting 64-bit systems only, you can do it the same way is on iOS.
精彩评论