-2

I wrote a setter method -

- (void)setMyProp:(MyProp *)myProp{
    _myProp = myProp;
}

How is underscore put before property name is working? I know this question has been asked, but they are about user setting property name to _myProp, some convention. I am not synthesizing or changing the property name. How this underscore is working?

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
user1559227
  • 1,021
  • 2
  • 10
  • 13
  • 1
    And here's another 16: http://stackoverflow.com/q/5582448/ http://stackoverflow.com/q/6049269/ http://stackoverflow.com/q/2371489/ http://stackoverflow.com/q/7174277/ http://stackoverflow.com/q/5659156 http://stackoverflow.com/q/837559/ http://stackoverflow.com/q/6146244/ http://stackoverflow.com/q/10651535/ http://stackoverflow.com/q/6124109/ http://stackoverflow.com/q/8145373/ http://stackoverflow.com/q/3521254/ http://stackoverflow.com/q/6064283/ http://stackoverflow.com/q/9696359/ http://stackoverflow.com/q/5521499/ http://stackoverflow.com/q/5466496/ http://stackoverflow.com/q/2114587/ – jscs Mar 06 '13 at 18:56

1 Answers1

1

If you are using latest version of LLVM, then the compiler creates @synthesize for you with the syntax:

@synthesize myProp=_myProp;

Therefore you are able to use _myprop even though you have not synthesized explicitly.

*SideNote: _myProp makes you access the property directly, while self.myProp will call accessor. Always use self.myProp

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140