Conversion to Automatic Reference Counting (ARC): 'Use of undeclared identifier' errors

时光毁灭记忆、已成空白 提交于 2020-01-31 15:23:09

问题


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

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:

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?


回答1:


I just hit the same problem.

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.

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.



来源:https://stackoverflow.com/questions/18780336/conversion-to-automatic-reference-counting-arc-use-of-undeclared-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!