Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Autocreate managed object context? #124

tonyxiao opened this Issue · 3 comments

3 participants


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.


Got it.

What do you think of this?

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

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.

@casademora 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.