views:

47

answers:

1

I recently tried to compile an older Xcode project (which used to compile just fine), and now I'm seeing a lot of errors of this form:

error: writable atomic property 'someProperty' cannot pair a synthesized setter/getter with a user defined setter/getter

The code pattern which causes these errors always looks like this:

// Interface:

@property (retain) NSObject * someProperty;

// Implementation:

@synthesize someProperty; // to provide the getter
- (void)setSomeProperty:(NSObject *)newValue
{
    //..
}

I can see why the error is being generated. I tell the compiler to synthesize my property accessors (both getter and setter), and then immediately afterward I override the setter manually. That code has always smelled a little off.

So, what is the proper way to do this? If I use @dynamic instead of @synthesize, I will have to write the getter as well. Is that the only way?

+1  A: 

I had the same problem and after doing a bit of research, here is my conclusion about this issue:

The compiler warns you about a @property that you declared as atomic (i.e. by omitting the nonatomic keyword), yet you provide an incomplete implementation of how to synchronize access to that property.

To make that warning disappear:

If you declare a @property to be atomic then do one of the following:

  • use @dynamic or
  • use @synthesize and keep the synthesized setter and getter or
  • provide a manual implementation of both the setter and the getter

If you declare the @property with (nonatomic) then you can mix manual and synthesized implementations of getters and setters.

octy