0

This is how I implement mine. Sometihng just doesn't fill right

-(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;
}

The objective is of course to ensure that currentAnchor is never accessed when it's changing. Am I doing this right?

user4951
  • 29,779
  • 47
  • 157
  • 270
  • No, not really. See [Atomic vs. nonatomic properties](http://stackoverflow.com/questions/588866/atomic-vs-nonatomic-properties/589348#589348) – jscs May 22 '12 at 16:53

1 Answers1

0

You are far better off using dead simple getter/setter implementations -- @synthesize ideally -- and move all change-response logic outside of the getter/setter. KVO works fine if you need single getter/setter response logic. You'll have to have an external transaction mechanism if you want to batch up a response to multiple property changes.

bbum
  • 160,467
  • 23
  • 266
  • 355