40

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?

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • 15
    Do you also have an explicit getter method? If so, the ivar won't be auto synthesized for you any more. – rmaddy Jul 08 '14 at 18:13
  • 4
    Yup, you need `@synthesize finished = _finished;` if you have both the getter and setter. This happens in earlier versions of Xcode too. – i_am_jorf Jul 08 '14 at 18:28
  • 2
    Found the same problem in SDWebImage - Toolkit.. You gave already the answer: manually add a @synthesize statement - or wait until release of xcode. – ThorstenC Jul 23 '14 at 17:55
  • @jeffamaphone this does not happens in earlier versions of xcode, OP probably has this error from the MWPhotoBrowser library, it used to work and compile perfectly in xcode 5, installed xcode 6 and suddenly got this error too. – Pochi Sep 18 '14 at 09:22

3 Answers3

40

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
Şafak Gezer
  • 3,928
  • 3
  • 47
  • 49
4

If you have an explicit getter, automatic property synthesized will be ignored.

Then you have to use @synthesize property = _property

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84
3

pod update

then your can now update to 3.7.1 that has fixed this bug.

iWill
  • 135
  • 1
  • 4