Enr*_*tyo 0 synchronization objective-c
我有一个同步的函数,但似乎我无法直接更改该块中的实例变量的值.
+(id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [super allocWithZone:zone];
//This is not allowed
something = @"hello";
//This is allowed
self.something = @"hello world!";
return sharedInstance;
}
}
return nil;
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我有一个我需要直接访问的变量(我不想合成该变量).我该如何解决这个问题?
归档时间: |
|
查看次数: |
839 次 |
最近记录: |