-2

In the objective c book i read the author always use property objects in the implementation like:

(I know we dont use synthesize anymore, unless we overriding the setter AND getter, but just for the example)

@synthesize suit, rank;

and in the stanford course if he need to use @synthesize he do:

@synthesize suit = _suit;

@synthesize rank = _rank;

and its getting me confused a bit. Is the _rank is to set the object to some value while the rank is to get it?

if yes, so the line: @synthesize rank = _rank; confuses me a bit...

would love to get some direction. tnx

Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
JohnBigs
  • 2,691
  • 3
  • 31
  • 61
  • This subject has been covered rather extensively already. You're better off looking at the "duplicates" rather than relying on an answer here. One thing to keep in mind, though, is that things changed somewhat with the more recent versions of Xcode, and with ARC. – Hot Licks Mar 10 '13 at 02:54

1 Answers1

4

@synthesize rank = _rank;

This instructs the compiler to generate a setter and/or getter as needed, using an ivar called _rank as the backing instance variable. It will create the ivar _rank if needed. [edit], meaning if it does not already exist.[/edit]

@synthesize rank;

This instructs the compiler to generate a setter and/or getter as needed using an ivar called rank (same name as the property itself)

And then with LLVM4, if you don't explicitly ask the compiler to @synthesize a @property, and you rely on the compiler to do this by default for you, then it will create an ivar called _rank by default.

Firoze Lafeer
  • 17,133
  • 4
  • 54
  • 48