Reputation: 9576
I have a question regarding best practices for Cocoa application architecture. If you look at the screenshot of my app's storyboard there is a view controller in the bottom left (which many controls) and there are two view controllers with table views in a split view controller, on the right side. I need to reference array controllers that are in each of the table view controllers (right side ) inside the controls view controller (left side).
How do I reach those array controllers all the way through the view hierarchy (which goes through different container views, etc.)?
I could of course just refer them in my app delegate, which is a singleton, and get them from there but we all know that this is not good OOP architecture.
Upvotes: 0
Views: 93
Reputation: 3529
You can create your own Singleton Class
for that. Like AppNameDataManager
then create properties and set them from the view controller where you have to set and get in view controller where you have to get.
#define SINGLETON_FOR_CLASS(classname)\
+ (id) sharedManager {
static dispatch_once_t pred = 0;\
static id _sharedObject = nil;
dispatch_once(&pred, ^{
_sharedObject = [[self alloc] init];
});\
return _sharedObject;
}
just import that class and get instance by calling [ClassName sharedManager]
Upvotes: 1