Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

objective c - What name does the auto-generated ivar take when I just declare a property in XCode 4.5 onwards?

Earlier I was on XCode 4.2 for a long time on Snow Leopard for a long time. I have made a straight jump to Mountain Lion with XCode 4.5 on with iOS 6 SDK and ARC.

A lot has changed for me. Just wanted to know, whether the naming style of default variables has changed ?

because in older XCode if I wont declare an ivar myself, it would take the same name as the property.

In 4.5, I declared a property (no synthesize required anymore!).

In the overidden setter, I am trying to use the variable as the same name as the property, say abc.

but XCode is not recognizing it and giving me suggestions of _abc !

Does the auto-generated ivar starts with _ now ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The automatically generated @synthesize statement uses instance variables prepended with an underscore:

@synthesize abc = _abc;

But an explicit @synthesize statement without instance variable

@synthesize abc;

is still equivalent to

@synthesize abc = abc;

for compatibility with older Xcode versions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...