In my projects, if I need an object which can be accessed globally, we create a Singleton manager object for it. And most of the time, it has to do with Settings.
The following code demonstrates a safe way to declare singleton objects:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
+ (SettingsManager *)sharedManager { static dispatch_once_t onceToken; static SettingsManager *manager; dispatch_once(&onceToken, ^{ if (manager == nil) { manager = [[SettingsManager alloc] init]; } }); return manager; } |