xCode 6 如何修复“使用未声明的标识符"用于自动属性合成? [英] xCode 6 how to fix "Use of undeclared identifier" for automatic property synthesis?

查看:22
本文介绍了xCode 6 如何修复“使用未声明的标识符"用于自动属性合成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xCode6 Beta 3,并且遇到了一个问题,以前编译良好的代码(xCode 5.1.1 或 xCode6 beta 2)突然开始给我使用未声明的标识符" 访问自动合成的实例变量时出错:

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:

- (void)setFinished:(BOOL)finished {
    [self willChangeValueForKey:@"isFinished"];
    _finished = finished;
    [self didChangeValueForKey:@"isFinished"];
}

//ERROR:
 Use of undeclared identifier '_finished'; did you mean 'finished'?

添加@synthesize finished = _finished; 会使错误消失,但是有没有办法强制 xCode6 Beta 3 使用下划线表示法使用自动属性合成?

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?

推荐答案

一开始我还以为是 beta 版本的 bug,但是今天看到 XCode 6 GM Seed 也出现了这种类型的错误,虽然我是尚未发现在哪些特定情况下.

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.

无论如何,修复方法是在@implementation 块中添加一个合成语句,显式声明 ivar 的名称以及属性:

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:

@synthesize property = _property

这篇关于xCode 6 如何修复“使用未声明的标识符"用于自动属性合成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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