我刚刚开始在Objective-C和我碰到这个例子来打造一个单身:澄清一个Objective-C的Singleton实例
+ (BNRItemStore *) sharedStore
{
static BNRItemStore *sharedStore = nil;
if (!sharedStore)
sharedStore = [[super allocWithZone:nil] init];
return sharedStore;
}
我明白了什么是他想要做的事 - 这是如果它存在,则返回相同的实例,如果不存在,则创建一个新实例。让我困扰的是这行:
static BNRItemStore *sharedStore = nil;
这会不会行重置sharedStore到零值,每次调用该方法?我没有看到的方法如何能够返回先前存在的情况下,如果该行一直将其设为零。
在此先感谢。
谢谢各位的全面的答案。了解。 – Jops