I am an iOS developer trying to put together a little OSX app.
One thing I cannot figure out is how to properly inject dependencies in my viewControllers.
This is my setup:
NSWindowController
|
+- NSSplitViewController
|
+- NSViewController
|
+- NSViewController
Now I want to inject my data stack into all viewControllers before they start loading their tableViews and ask for some data.
1st attempt:
Coming from iOS I hook into [AppDelegat applicationDidFinishLaunching]
to create my data stack and set it on the root view controller for passing along to its children.
Problem: It's too late – [NSViewController viewDidLoad]
gets called before that (what?). My TableView starts asking for data before I had the chance to set it up.
Next thing I did was to do some logging to find out how the app setup cycle really works. I found out the live-cycle methods get called in that order:
[DKDSplitViewController viewDidLoad]
[DKDTableViewController viewDidLoad]
[DKDWindowController windowDidLoad]
[DKDWindowController awakeFromNib]
[AppDelegate applicationDidFinishLaunching:]
That seems quite weird to me, children being created before their parents...
Am I doing something wrong or are these the rules of nature on OSX?
So as it looks, I should do my setup in my SplitViewController. Somehow that feels wrong.
Ok, so how do I properly inject setup data into my view controllers on OSX?