1

Possible Duplicate:
Synthesized property and variable with underscore prefix: what does this mean?

I've seen both of these in code; what's the difference?

@synthesize fooBar;

@synthesize fooBar=_fooBar;
Community
  • 1
  • 1
William
  • 21
  • 2
  • 3
    Which is itself probably a dupe: [1](http://stackoverflow.com/questions/3521254) [2](http://stackoverflow.com/questions/822487/) [3](http://stackoverflow.com/questions/2371489) [4](http://stackoverflow.com/questions/5582448/) [5](http://stackoverflow.com/questions/837559/) and [so on...](http://stackoverflow.com/search?q=objc+property+underscore) Please search before posting; the system helps you do this by showing links to related questions while you're typing yours in. – jscs May 19 '11 at 20:12

1 Answers1

3

@synthesize fooBar; creates accessors for the property fooBar using an instance variable with the same name for storage, while the =_fooBar tells the compiler to use the instance variable named _fooBar as storage instead. You don't need to use the =... if you have your instance variables and properties identically named, and you do otherwise.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123