I watched Stanford iTunes U's course on iOS (cs193p) , where the teacher explicitly says to always specify the ivar name when used @synthesizeto avoid problems like
@synthesize
@synthesize name = _name;
But when I looked at Cocoa's documentation of declared properties, I really did not see this or in any other code example.
This leads me to the question, why is this needed? Isn't that enough to just use a @synthesizeproperty name? Are there any specific issues that this can help avoid?
ivars , , . :
: self.name = newName; : name = newName;
self.name = newName;
name = newName;
. , , . , , - init, dealloc getters seters.
init
dealloc
ivar, , . , :
@synthesize name; @synthesize name = name;
, , name = name, , .
name = name
, , name = _name, ivar . , , , , , .
name = _name
This is definitely not redundant, because it @synthesize name = _name;has a different meaning than @synthesize name;. If you want to name your Ivars differently than your properties, this is basically a matter of personal preference. Both options are great.
@synthesize name;