当我在XCode 4.5中声明属性时,自动生成的ivar会采用什么名称? [英] What name does the auto-generated ivar take when I just declare a property in XCode 4.5 onwards?

查看:107
本文介绍了当我在XCode 4.5中声明属性时,自动生成的ivar会采用什么名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早些时候我在Snow Leopard很长一段时间都在XCode 4.2上。
我已经使用XCode 4.5直接跳转到Mountain Lion,使用iOS 6 SDK和ARC。

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 ?

因为在旧的XCode中,如果我不自己声明一个ivar,它将采用与物业。

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

在4.5中,我宣布了一个属性(不再需要合成!)。

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

在over over setter,我试图使用变量作为属性的同名,比如说abc。

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

但是XCode没有认出它并给我建议_abc!

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

自动生成的ivar是否以_现在开始?

Does the auto-generated ivar starts with _ now ?

推荐答案

自动生成的 @synthesize 语句使用前缀为下划线的实例变量:

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

@synthesize abc = _abc;

但是没有实例的显式 @synthesize 语句变量

But an explicit @synthesize statement without instance variable

@synthesize abc;

仍相当于

@synthesize abc = abc;

与旧Xcode版本的兼容性。

for compatibility with older Xcode versions.

这篇关于当我在XCode 4.5中声明属性时,自动生成的ivar会采用什么名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆