Why doesn't Apple have classes like pure singleton, for example, although the UIApplication class gives you access to the UIApplication singleton, for example:
UIApplication *sharedApplication = [UIApplication sharedApplication];
Nothing prevents you from explicitly creating an instance of UIApplication, for example:
UIApplication *newApplication = [[UIApplication alloc] init];
The result, however, is an exception. The exception clearly states that only one instance of the UIApplication class can be available at any time.
Then why not get a clean singleton by returning the same instance to the default initializer?
I ask this question in order to have clarity when creating a singleton in my project in order to keep track of which way is better.
source
share