Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Autocreate managed object context? #124

tonyxiao opened this Issue · 3 comments

3 participants

tonyxiao Magical Panda Software Saul Mora

One problem with calling + (void) setupCoreDataStack; from the applicationDidFinishLaunching:(UIApplication *) withOptions:(NSDictionary *) as the documentation suggested is that bindings in views to managedObjectContext get called before applicationDidFinishLaunching. Perhaps ManagedObjectContext could also be lazily created and automatically setup just like ManagedObjectModel and PersistentStoreCoordinator?

static BOOL shouldAutoCreateManagedObjectModel_;
static BOOL shouldAutoCreateDefaultPersistentStoreCoordinator_;

I can write the lazy creation code but I am wondering if there is any design decision involved to not auto create the managedObjectContext.

Magical Panda Software

Got it.

What do you think of this?

+ (NSManagedObjectContext *)MR_defaultContext
    if (!defaultManageObjectContext_) 
        @synchronized (self) 
            if (!defaultManageObjectContext_)
                [MagicalRecordHelpers setupCoreDataStack];
    return defaultManageObjectContext_;
Saul Mora

I think I'd still be more apt to putting the setup stuff in the awakeFromNib method, or in your AppDelegate's init method, or even from the main method, prior to launching your app delegate. The setup methods are meant to do things more precisely like setting up a core data stack with some alternative options. I setting up the default context setter method is not the proper place in my opinion as there are more viable options here.

Saul Mora casademora closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.