iOS Pass NSManagedObjectContext from my app delegate
iOS Pass NSManagedObjectContext from my app delegate
- Subject: iOS Pass NSManagedObjectContext from my app delegate
- From: Philip Vallone <email@hidden>
- Date: Thu, 20 Jan 2011 19:25:28 -0500
Hi,
Whats the best way to pass a NSManagedObjectContext object from an app delegate to other view controllers?
Currently, my NSManagedObjectContext is retained like this in my app delegate:
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@private
NSManagedObjectContext *managedObjectContext_;
}
and in my implementation:
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext_ != nil) {
return managedObjectContext_;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}
In my view controllers, I create another NSManagedObjectContext Object and pass the reference like this:
@property (nonatomic, retain) NSManagedObjectContext *context;
Implementation:
CameraPlanAppDelegate *appDelegate = (CameraPlanAppDelegate *)[[UIApplication sharedApplication] delegate];
context = [appDelegate managedObjectContext];
Is this correct? Do I need to release "context" on my view controller? If I release it, don't I release all references to it?
Thanks.
Phil_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden