Many recommends AppDelegate
and sure it does work because AppDelegate
itself is a singleton, but, you know, you should not put a piece of data into a class that it does not belong to (that's what people call object oriented programming). Anyway, it does work, and probably be fine if you want to save a bit of time, a bit of trouble creating a new class, and are happy with violating some old object oriented principles.
Notification Center should be used for notifications only: some event happens in one place, and another object wants to get notified, maybe along with some data regarding that event. Not the best for pure data sharing. Performance is not a problem since it nails down to function calls (assuming you're passing pointers only, not copying some big data).
IMHO, you have two options (at least):
Create a singleton class dedicated to contain the data. Lot of resources tell you how to do this, but basically a singleton class in Objective-C looks like this
@interface S
+(S*)singleton;
@end
@implementation S
+(S*)singleton { // iOS sometimes use 'sharedInstance' instead of 'singleton'
static S* o = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
o = [[self alloc] init];
});
return o;
}
@end
And whenever you need to access it
[S singleton] ...
The second option is applicable when there is only one instance of A in the whole application life time (this happens very often if A is a root view controller). In this case, you can just turn A into a singleton. The code in your app delegate will look like this
A* a = [A singleton];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:a];
And E can just access all A's data with [A singleton]