Does the ivar name indicate @synthesize is considered redundant or good practice?

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 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?

+5
source share
3 answers

ivars , , . :

: self.name = newName; : name = newName;

. , , . , , - init, dealloc getters seters.

+6

ivar, , . , :

@synthesize name;
@synthesize name = name;

, , name = name, , .

, , name = _name, ivar . , , , , , .

+1

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.

0
source

All Articles