On Jan 20, 2011, at 5:25 PM, Philip Vallone wrote:

> Hi,
> 
> Whats the best way to pass a NSManagedObjectContext object from an app 
> delegate to other view controllers?

Did you use the Xcode template for making a CoreData application?

> Currently, my NSManagedObjectContext is retained like this in my app delegate:
> 
> @property (nonatomic, retain, readonly) NSManagedObjectContext 
> *managedObjectContext;

If you have declared the property to be read-only, then the retain keyword is 
not necessary. Retain and assign are only necessary if it's a read/write 
property, since they tell the synthesizer what to do with new values (if 
@synthesize is in use).

> @private
>    NSManagedObjectContext *managedObjectContext_;
> }

You generally don't need to declare instance variables as private in an 
application unless you know your class will be subclassed. In most cases, the 
default protection level is good enough.

> CameraPlanAppDelegate *appDelegate =  (CameraPlanAppDelegate 
> *)[[UIApplication sharedApplication] delegate];  
> context = [appDelegate managedObjectContext];
> 
> Is this correct?

Yes.

> Do I need to release "context" on my view controller?

No. Re-read the memory management rules.

> If I release it, don't I release all references to it?

No. Re-read the memory management rules. 
<http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH>

Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to