Objective c 如何在目标C中实现原子属性(带或不带ARC)?
这就是我如何实现我的。有些东西就是填不好Objective c 如何在目标C中实现原子属性(带或不带ARC)?,objective-c,multithreading,xcode4.3,synchronized,Objective C,Multithreading,Xcode4.3,Synchronized,这就是我如何实现我的。有些东西就是填不好 -(void)setCurrentAnchor:(CLLocation *)currentAnchor { //CM(@"set current anchor"); /*@synchronized (self) { }*/ if (_currentAnchor==currentAnchor) { return; } //[Tools DoSomethingWithS
-(void)setCurrentAnchor:(CLLocation *)currentAnchor
{
//CM(@"set current anchor");
/*@synchronized (self)
{
}*/
if (_currentAnchor==currentAnchor)
{
return;
}
//[Tools DoSomethingWithSynchronize:^{
@synchronized(self){
_currentAnchor=currentAnchor;
[Timer searchCriteriaChanged];
[cachedProperties setDistanceForAllBiz];
}
//}];
}
-(CLLocation *)currentAnchor
{
//[Tools DoSomethingWithSynchronize:^{
//}];
@synchronized(self){
} //Empty @synchronized section just to block every other thread
[self setCurrentLocationasAnchorifNil];
return _currentAnchor;
}
当然,我们的目标是确保currentAnchor在更改时永远不会被访问。我这样做对吗?您最好使用死气沉沉的简单getter/setter实现-@synthesis-idental-并将所有更改响应逻辑移到getter/setter之外。如果需要单getter/setter响应逻辑,KVO可以正常工作。如果要批量响应多个属性更改,则必须有一个外部事务机制。不,不太可能。看见