neoneye
neoneye

Reputation: 52161

why is ivars needed in Cocoa when they aren't needed in iOS?

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

Upvotes: 0

Views: 155

Answers (1)

Jens Ayton
Jens Ayton

Reputation: 14558

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.

Upvotes: 7

Related Questions