我有一个像这样的Singleton设置:
static Universe *instance;
+ (Universe *)instance { return instance; }
+ (void)initialize
{
static BOOL initialized = NO;
if(!initialized)
{
initialized = YES;
instance = [[Universe alloc] init];
}
}
- (id) init
{
self = [super init];
if (self != nil) {
self.showHistory = YES;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
但现在我意识到我想从Interface Builder中实例化它.我正在考虑切入init这样的方法
if (instance)
return instance;
Run Code Online (Sandbox Code Playgroud)
这是一个坏主意吗?我更喜欢IB来获取已经在+initialize方法中创建的实例.
objective-c ×1