0

Possible Duplicate:
@property and @synthesize

What does it mean when a class has a property, but has no variable for it? rather I see things like:

@interface myClass : someClass

    @property (nonatomic,retain) UIButton* button;

@end

and in the implementation:

@synthesize button = _button;

So who is _button?

What does the @synthesize do when declared like this?
Does this mean that the class now has a private var called _button? Can I treat _button as a private var of the class?

Community
  • 1
  • 1
Jackson
  • 264
  • 2
  • 9

1 Answers1

2

Does this mean that the class now has a private var called _button? Can I treat _button as a private var of the class?

Yes, this is a new feature of the Clang compiler - it automatically creates instance variables for properties, and the ivar has @private access level and has the _namwOfProperty if the name of the property is nameOfProperty.

  • It's even more restricted than `@private`: a synthesized ivar is only visible in the file where the synthesize directive is located. – jscs Oct 28 '12 at 23:08
  • @JoshCaswell apart from categories, isn't that the same as `@private`? –  Oct 28 '12 at 23:11
  • Right, an `@private` ivar is available inside of a category on the class, but a synthesized variable isn't. – jscs Oct 28 '12 at 23:58