It seems like you may be running into the problem of overusing Singletons for managing controllers that don't need to be Singletons. This may be useful:
I recently reworked my entire program from singleton to passing objects along as they're needed. Note that singleton and shared global objects are not identical, and Apple's own classes use sharedObject
or defaultObject
which instantiates and returns a shared instance, but nothing is stoping you from actually creating another instance of the class for your own needs.
Singleton on the other hand restricts the object to a single instance, and this means forgoing the ability to have two instances (which may be needed in the future) for the benefit of having complete access from anywhere. In that sense, you really only need the total access part and not the restriction of a single instance, so you might consider the sharedObject
pattern. Here's an example:
// Up the top in the .m file
static MySharedClass *sharedInstance;
// A class method to return the shared instance
+ (MySharedClass *)sharedInstance {
if (!sharedInstance) {
sharedInstance = [[MySharedClass alloc] init];
}
return sharedInstance;
}
Having said that, I would consider structuring your program to pass objects as they are needed rather than setting up everything globally for access by everything. Otherwise the code you write with overuse of singleton/global objects is far more coupled and can't be pulled out of the current project and used elsewhere, and it makes debugging harder because you need to consider the global state of these manager classes.
I would create my main controller (ViewController) which will then instantiate the other controller classes needed and pass resources between them. This NSArray of UIViews you mention would be stored as high in the chain as is needed, presumably right up the top. This Presenter would then create the LayoutManager and pass the needed objects to it for further work. And in the same way, I would pass these objects to the BlockManager and ColorManager.