In objective-c we declare only as property without instance variable?

I’m reading about core data and I noticed (again) in application delegate file:

@interface AppController : NSObject <UIApplicationDelegate> {

UINavigationController *navigationController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

where the we have only the decleration of properties without the instance variables.

By googling around I found that:

In Objective-C 2.0 on either of the modern runtimes (ie, Intel 64bit and ARM) properties can be added to classes ‘dynamically’ (that is, at runtime but only before the creation of any instances — not particularly dynamic compared to the rest of the runtime). However, this can’t be done on either of the two older runtimes (ie, Intel 32bit and PowerPC). It’s therefore not really something you want to use on shipping software for the Mac or during development for iOS (since the simulator is a 32bit Intel application and can’t create instance variables at runtime)

So, In Objective-C 2.0, synthesized properties will automatically create the corresponding ivars as required.

Leave a Reply

Your email address will not be published. Required fields are marked *