0
這是我如何實施我的。 Sometihng只是不能正確填寫如何在目標C中實現原子屬性(有或沒有ARC)?
-(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在更改時不會被訪問。我做對了嗎?
不,不是真的。請參閱[原子與非原子屬性](http://stackoverflow.com/questions/588866/atomic-vs-nonatomic-properties/589348#589348) –