Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 7开发人员-@synthesis未自动创建IVAR_Ios_Objective C_Ios7_Synthesize - Fatal编程技术网

iOS 7开发人员-@synthesis未自动创建IVAR

iOS 7开发人员-@synthesis未自动创建IVAR,ios,objective-c,ios7,synthesize,Ios,Objective C,Ios7,Synthesize,我目前正在使用最新版本的Xcode(v5.0.2),我的应用程序的部署目标是iOS 7.0 我的问题是,无论在哪个类中,我都可以在头中设置属性 例如:@property(强,非原子)NSString*firstName 在实现文件中,我可以很好地合成它 例如:@firstName 我的问题是我不能在代码中使用\u firstName。我在其他项目中使用了自动IVAR(属性名称前面带有下划线) Xcode抱怨并告诉我将其更改为不带下划线的属性名称。我不明白为什么这个项目没有为我自动创建带有下划线的

我目前正在使用最新版本的Xcode(v5.0.2),我的应用程序的部署目标是iOS 7.0

我的问题是,无论在哪个类中,我都可以在头中设置属性

例如:
@property(强,非原子)NSString*firstName

在实现文件中,我可以很好地合成它

例如:
@firstName

我的问题是我不能在代码中使用
\u firstName
。我在其他项目中使用了自动IVAR(属性名称前面带有下划线)

Xcode抱怨并告诉我将其更改为不带下划线的属性名称。我不明白为什么这个项目没有为我自动创建带有下划线的IVAR。我知道在旧版本的Objective-C中,您必须自己完成这项工作,但在iOS 7中却没有


谢谢

您可以完全跳过
@synthesis
,它将创建带下划线的IVAR。如果您不指定变量名(
@synthesis firstName=\u firstName;
),而执行
@synthesis
),它将创建不带下划线的变量。

跳过
@synthesis
,这样就可以了。因为您使用的是新的XCode版本,所以在这种情况下并不真正需要它。请查看(和)。

不要麻烦使用@synthesis(除非它是NSManagedObject子类)。但是,很少有人会使用直接ivar。在init方法之外,您应该始终使用self.firstName。

@synthesis
为您的属性创建ivar

在这行中

@synthsizefirstname=otherName

其中,
firstName
是您的财产名称,
otherName
是您的ivar名称

在您的行业中

@firstName=
@synthesis firstName=firstName

因此属性和ivar是相同的,即
firstName

如果您没有编写任何
@synthesis

然后编译器将

@synthesis firstName=\u firstName

其中,
firstName
是属性名,
\u firstName
是ivar名

我会说“在init、dealoc和getter/setter方法之外”。