Search code examples
iphonecocoa-touchcore-datauimanageddocument

Is the managedObjectContext initialized before the managed document is created/opened


I am accessing Core Data using UIManagedDocument, what I want to know is that once I have instantiated the managedDocument (before creating or opening) it would seem that the managedObjectContext has been setup/initialized for future use. The reason that I ask is that I want to pass the managedObjectContext to a controller at startup and then wait there whilst the managedDocument/database is created or opened for use.


Solution

  • The answer is yes, as soon as the UIManagedDocument is instantiated the managedObjectContext is setup and ready to be passed to any controllers that need it. This is also done before the actual Core Data URL on disk is either created or opened, so you don't have to worry about waiting for that to pass/assign the managedObjectContext, you do on the other hand need the URL to have been created/openened if you want to read or write any data to or from Core Data.