xcode – 转换为自动引用计数(ARC):’使用未声明的标识符’错误
发布时间:2020-12-14 19:07:34 所属栏目:百科 来源:网络整理
导读:在一个非常大的项目中我到处使用自动合成属性: //MyClass.h file:@interface MyClass : NSObject@property (nonatomic,retain) NSString *deviceName;@property (nonatomic,retain) NSString *deviceID;@end//MyClass.m file:#import "MyClass.h"@implement
在一个非常大的项目中我到处使用自动合成属性:
//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版本中编译得很好. 这是什么原因?我是否必须手动创建数百个实例变量并立即手动@synthesize它们?苹果公司在所有WWDC上宣传的“少写代码”理念是否会退后一步呢? 解决方法
我刚刚遇到同样的问题.
在Apple的指导下,我虔诚地使用自我.在init之外的init和_. 我发现最简单的方法是: @synthesise deviceName = _deviceName; 改变所有引用只是愚蠢,痛苦和错误,对于只读变量,甚至不是一个选项. 自动完成在设置合成语句时非常聪明,而你只需要它们用于你将要在init中访问的内容. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |