Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

ios - xCode 6 how to fix "Use of undeclared identifier" for automatic property synthesis?

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'?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...