I just can not fully understand one moment. Here is the usual implementation of a singleton:
+ (instancetype)sharedInstance { static MyClass *sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[MyClass alloc] init]; }); return sharedInstance; } Then use Singleton 2 times:
Singleton *inst1 = [Singleton sharedInstance]; Singleton *inst2 = [Singleton sharedInstance]; I correctly understand that when you re-execute the line (during the second call):
static MyClass *sharedInstance = nil; Assignment to nil will not occur, because the variable is declared inside a static function? Those. when the static function is called again, will the string be simply ignored?
Where can I read more about this situation? (declaration and initialization of variables inside a static method)