Search code examples
objective-cpropertiessynthesize

Local declaration of 'photo' hides instance variable


The compiler shows me a warning as Local declaration of 'photo' hides instance variable. I don't understand what's going on.

// PTKData.h

@interface PTKData : NSObject {

    UIImage *photo;
}

@property ( nonatomic, retain ) UIImage *photo;

- ( void ) doSomething: ( UIImage * )photo;

@end

// PTKData.m

@synthesize photo = _photo;

- ( void ) doSomething: ( UIImage * )photo {

    _photo = photo;
}

On my understanding, @synthesize photo = _photo renames photo to _photo when existing the same local variable name in a method. I can't look for the problem causing the warning in my code.

Thank you in advance.


Solution

  • In your code, you are creating two ivar's:

    One with this line at the top:

    UIImage *photo;  // Creates an ivar called photo
    

    And the second one when you synthesize photo:

    @synthesize photo = _photo; // Creates an ivar called _photo
    

    I'm guessing that you only want the second one, and can simply delete the entire first line. (It isn't associated with self.photo at all anyway, like _photo is.)