• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iOS Pass NSManagedObjectContext from my app delegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iOS Pass NSManagedObjectContext from my app delegate


  • Subject: Re: iOS Pass NSManagedObjectContext from my app delegate
  • From: Nick Zitzmann <email@hidden>
  • Date: Thu, 20 Jan 2011 17:46:13 -0700

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 (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

  • Follow-Ups:
    • Re: iOS Pass NSManagedObjectContext from my app delegate
      • From: Eeyore <email@hidden>
    • Re: iOS Pass NSManagedObjectContext from my app delegate
      • From: Philip Vallone <email@hidden>
References: 
 >iOS Pass NSManagedObjectContext from my app delegate (From: Philip Vallone <email@hidden>)

  • Prev by Date: iOS Pass NSManagedObjectContext from my app delegate
  • Next by Date: Re: iOS Pass NSManagedObjectContext from my app delegate
  • Previous by thread: iOS Pass NSManagedObjectContext from my app delegate
  • Next by thread: Re: iOS Pass NSManagedObjectContext from my app delegate
  • Index(es):
    • Date
    • Thread