ios xCode 6 如何修复“使用未声明的标识符”以进行自动属性合成?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24638826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xCode 6 how to fix "Use of undeclared identifier" for automatic property synthesis?
提问by Alex Stone
I'm using xCode6 Beta 3, and am running into an issue where a code which previously compiled fine (xCode 5.1.1 or xCode6 beta 2) suddenly started to give me "Use of undeclared identifier"errors when accessing an automatically synthesized instance variable:
我正在使用 xCode6 Beta 3,并且遇到了一个问题,以前编译良好的代码(xCode 5.1.1 或 xCode6 beta 2)在访问自动合成的实例变量时突然开始给我“使用未声明的标识符”错误:
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"];
_finished = finished;
[self didChangeValueForKey:@"isFinished"];
}
//ERROR:
Use of undeclared identifier '_finished'; did you mean 'finished'?
Adding @synthesize finished = _finished;
makes the error go away, but is there a way to force xCode6 Beta 3 to use automatic property synthesis using underscore notation?
添加@synthesize finished = _finished;
会使错误消失,但是有没有办法强制 xCode6 Beta 3 使用下划线表示法使用自动属性合成?
采纳答案by ?afak Gezer
At first I thought it was a beta version bug, but today I saw that this type of errors occur on the XCode 6 GM Seed also, though I'm yet to discover in which particular cases.
起初我认为这是一个测试版的错误,但今天我看到 XCode 6 GM Seed 上也发生了这种类型的错误,尽管我还没有发现是在哪些特定情况下。
Anyway, the fix is to add a synthesize statement in the @implementation block, explicitly declaring the name of the ivar as well as the property:
无论如何,修复方法是在@implementation 块中添加一个综合语句,显式声明 ivar 的名称以及属性:
@synthesize property = _property
回答by Jakub Truhlá?
If you have an explicit getter, automatic property synthesizedwill be ignored.
如果你有一个显式的getter,自动合成的属性将被忽略。
Then you have to use @synthesize property = _property
然后你必须使用 @synthesize property = _property
回答by iWill
pod update
豆荚更新
then your can now update to 3.7.1 that has fixed this bug.
那么您现在可以更新到已修复此错误的 3.7.1。