And*_*nov 2 singleton objective-c ios automatic-ref-counting ios6
所以我的理解是,如果该方法没有实现初始化对象的新实例,那么在方法名称中使用init是不可取的.但是,单例类型的情况是什么?如果我做这样的事情:
+ (MyClass*) sharedInstance {
__block MyClass *sharedInstance = nil;
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
sharedInstance = [[MyClass alloc] init];
});
return sharedInstance;
}
Run Code Online (Sandbox Code Playgroud)
然后有另一种方法:
- (void) initializeInstance {
// Do some stuff
// Never call the init method
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,是否会有额外的保留周期或其他奇怪的ARC行为?
| 归档时间: |
|
| 查看次数: |
195 次 |
| 最近记录: |