In Cocoa, Storyboard's first view controller will call viewDidLoad
(on the first view controller) before AppDelegate
's applicationDidFinishLaunching
is called.
Since I am grabbing my NSManagedObjectContext
in applicationDidFinishLaunching
, I need to wait for applicationDidFinishLaunching
before loading my data.
In other words, in viewDidLoad
, I don't yet have my NSManagedObjectContext
.
What I'm doing now:
I'm adding an applicationDidFinishLaunching
observer in my viewDidLoad
, and load the data when that is triggered.
So (in order):
1. ViewController is adding an applicationDidFinishLaunching
observer.
2. AppDelegates runs its applicationDidFinishLaunching
and triggering the observer.
3. I can load the data from my ViewController.
I realized I'm relaying on viewDidLoad
to be called before applicationDidFinishLaunching
. If that order is changed, the observer will be added after applicationDidFinishLaunching
and data will not load.
Would it be 'safer' to let my 'CoreDataManager' get the NSManagedObjectContext
from AppDelegate directly in its init
?