如何在多个nib文件中共享单个NSController
?就像"共享用户默认控制器"由Xcode提供?
答案 0 :(得分:0)
这是我用于这种情况的代码:
@implementation MySingletonClass
static MySingletonClass* instance = 0;
- (id) init {
if ( instance )
return instance;
return ( instance = self = [super init] );
}
+ (MySingletonClass*) shared {
static dispatch_once_t pred;
dispatch_once(&pred, ^{
instance = [[MySingletonClass alloc] init];
});
return instance;
}
@end