I am setting up a Core Data model (UIManagedDocument
) in my AppDelegate and was curious about how I might inject a reference to the NSManagedObjectContext
into my (storyboards) Initial viewController.
I could access it directly in the viewControllers viewDidLoad
using [[[UIApplication sharedApplication] delegate] sampleDatabase] managedObjectContext]
and then pass it onto further controllers using prepareForSegue
.
I was just wondering if there is an initial segue (or mechanism) that would allow me to pass (or inject) the managedObjectContext into that initial viewController without having to access it using the appDelegates shared instance once inside the controller?
When you use a storyboard, the initial view controller is set as the rootViewController
property of your delegate just before application:didFinishLaunchingWithOptions:
is called.
You should be able to use a cast on that reference to set a property, assuming your Core Data structure is set up by then.