Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writable atomic property 'result' cannot pair a synthesized setter/getter with a user defined setter/getter [duplicate]

Possible Duplicate:
error: writable atomic property cannot pair a synthesized setter/getter with a user defined setter/getter

I am getting the following warning: Writable atomic property 'result' cannot pair a synthesized setter/getter with a user defined setter/getter

This is how I setter/getter it:

@property (retain, getter=getResult) NSString *result;
@synthesize result;

I get the warning in the bolded/italicized line below:

***- (NSString *)getResult***
{
    if (result == nil)
        self.result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
    return result;
}

Any ideas on how to fix it?

Thanks!

like image 822
SimplyKiwi Avatar asked Aug 09 '11 03:08

SimplyKiwi


2 Answers

Synthesizing an atomic property generates a getter and setter which use a lock to ensure that the value is always fully retrieved or set in a multithreaded environment.

Either change your property declaration to:

@property (nonatomic, retain) NSString *result;

Or define both accessors yourself and implement your own locking mechanism to guarantee atomicity.

like image 184
titaniumdecoy Avatar answered Oct 24 '22 20:10

titaniumdecoy


When you set the @property for a setter, the compiler will automatically make a setter that goes by the name getResult(you can not see it though). So, when you make a setter yourself, the compiler warns you that it has already done that for you. But this does not cause any issues with functionality because, as you might've seen with breakpoints, this code is still called. So, you can either remove the code for making a setter in the @property or you can make a setter that takes does not have the same name and does not take the same arguments as the default setter and call it yourself, like

- (NSString *)getResult(id data){}
like image 41
tipycalFlow Avatar answered Oct 24 '22 20:10

tipycalFlow