转换为自动引用计数(ARC):“使用未声明的标识符”错误 [英] Conversion to Automatic Reference Counting (ARC): 'Use of undeclared identifier' errors

查看:188
本文介绍了转换为自动引用计数(ARC):“使用未声明的标识符”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个非常大的项目中,我使用了自动合成的属性:

In one of the very big projects I used auto-synthesized properties everywhere:

//MyClass.h file:
@interface MyClass : NSObject

@property (nonatomic, retain) NSString *deviceName;
@property (nonatomic, retain) NSString *deviceID;

@end

//MyClass.m file:
#import "MyClass.h"

@implementation ApplicationStatus
// no @synthesize used at all.

-(void)dealloc{

    [_deviceName release]; // gives errors only while converting to ARC with LLVM 5.0
    [_deviceID release];

    [super dealloc];
}

@end

上面的代码编译得很好非ARC模式,以及在ARC转换过程中在较旧的Xcode版本中。
当尝试使用最新的LLVM 5.0编译器(最新的Xcode)进行转换时,它给我几百万的错误:

The code above compiles well in non-ARC mode and also in older Xcode versions during ARC conversion process. When trying to convert in using newest LLVM 5.0 compiler (newest Xcode) it gives me millions of errors:

这是什么原因?我必须手动创建数百个实例变量并手动合成它们吗?这不是从写少代码的哲学退步的苹果广告在所有WWDCs?

What is the cause of this? Do I have to manually create hundreds of instance variables and @synthesize them manually now? Wouldn't that be step back from 'write less code' philosophy Apple advertised on all WWDCs?

推荐答案

问题。

按照苹果的指导,我虔诚地使用 self。 outside init 中的 init 中的 _

Following Apple's guidance, I religiously use self. outside init and _ in init. This breaks as you wrote, when migrating to ARC in Xcode 5.

我发现最简单的方法是:

I found the easiest way is to:

@synthesise deviceName = _deviceName;

更改所有引用只是愚蠢,痛苦和错误,甚至一个选项。

Changing all the references is just dumb, a pain, and wrong, and for read only variables, not even an option.

自动完成在设置synthesise语句时非常聪明,你只需要它们来访问 init

The autocomplete is pretty smart in setting up the synthesise statements, and you only need them for the stuff you're going to access in init.

这篇关于转换为自动引用计数(ARC):“使用未声明的标识符”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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