• 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
iOS Pass NSManagedObjectContext from my app delegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: iOS Pass NSManagedObjectContext from my app delegate
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: best way of making a constant animation
  • Next by Date: Re: iOS Pass NSManagedObjectContext from my app delegate
  • Previous by thread: Re: NSBlockOperation with +[sendSynchronousRequest sendSynchronousRequest:...] or async?
  • Next by thread: Re: iOS Pass NSManagedObjectContext from my app delegate
  • Index(es):
    • Date
    • Thread