45

I've got an incredibly annoying issue that is hampering my workflow. In my project I have "User of undeclared identifier" errors all over. They are all in reference to a single class, specifically a Theme class. I checked for any circular referencing with my imports, none. I'm really confused.

Here is a screenshot of the errors. I would post errors in the Build Log for more detail, but there aren't any. It builds and runs just fine...

enter image description here

I've tried cleaning, deleting the derived data... Any ideas?

rnystrom
  • 1,866
  • 2
  • 20
  • 45
  • 1
    Are you linking to all the right libraries? – Chris Trahey Aug 27 '12 at 21:49
  • 1
    Did you try restarting Xcode? I've had these types of errors occur when changing filename extensions (`.m` to `.mm`, mainly), and restarting Xcode usually fixes it. – Richard J. Ross III Aug 27 '12 at 21:53
  • You're both right. Forgot to recompile my static library. Should have made edits in the project separately. Did that and it still persisted. Restarted Xcode and now its all gone. Thanks guys! edit: nevermind, still happening :( – rnystrom Aug 27 '12 at 21:54
  • I am facing same problem in xcode 7.3.Please provide me solution for same – Donal Oct 12 '16 at 10:41
  • Even in modern, 2017 XCode, this can happen. Annoying. Sometimes a restart helps? – Fattie Jul 25 '17 at 19:48

11 Answers11

87

I was having the same problem and noticed that all of the undeclared identifiers were declared in files that were in my pch file.

With this in mind I deleted one of the #import lines from the pch file and recompiled which failed as expected. I then put the deleted line back in, recompiled and it compiled normally with all the false errors gone.

Hopefully this simple solution helps a few of you out if the above solutions don't.

Newtz
  • 1,303
  • 11
  • 9
  • This solution worked for me. I guess Xcode just needed a proper refresher. – runmad Jan 18 '13 at 02:47
  • That worked for me as well. I had the same issue; that all the complaints centered on things declared in files referred to in my PCH file. Excellent. Thanks! – Gallymon Nov 21 '13 at 19:45
  • Thanks sorted out the problem for me too. How flipping annoying. I hope they fix this bug soon! – Robert J. Clegg May 27 '14 at 10:24
  • That worked for me on Xcode 5.1.1 after a Clean. Man That's really frustrating. Not that the warning is stopping me from building and running, but it's still annoying as hell. – Ben Sep 02 '14 at 10:09
  • 2
    @Ben Agreed. This happened to me when updating my Parse.com SDK. This is ridiculous and, considering the "fix" is 2 years old (and from Xcode 4) and still failing in Xcode 6, this is SUPER ridiculous! Glad someone else knew how to fix this! – mbm29414 Sep 18 '14 at 18:23
  • So apparently this is still an issue, and this fix still works. – BP. Feb 20 '15 at 01:27
  • This seems to happen every time I create a new branch in subversion to work in. From now on when I see it I will know how to fix it - thx! This is still necessary in Xcode 6.4. -rrh – Richie Hyatt Jan 05 '16 at 20:12
  • This issue is still there in Xcode 7.3. This solution fixed it for me tho. Apple really needs to look into these annoying errors. – NSNoob May 21 '16 at 05:27
9

These kinds of errors are quite common with Xcode, unfortunately. It would be great if it would auto-refresh its error list all the time, but it doesn't always. When this happens, I strongly suggest that you restart Xcode, which will flush its error cache and hopefully solve your issues.

John Topley
  • 107,187
  • 45
  • 188
  • 235
Richard J. Ross III
  • 53,315
  • 24
  • 127
  • 192
  • Ended up working. Shut her down when I went to sleep. Fired up and nothing is wrong. Errors like these, when I HAVE to use this IDE, drive me crazy when I do this professionally... – rnystrom Aug 28 '12 at 12:32
  • 2
    @rnystrom actually, there is another IDE that I know about, called AppCode by JetBrains. I would check it out, there's a 30 day trial for sure. – Richard J. Ross III Aug 28 '12 at 16:20
4

How are you including this class? In most cases I just include the class explicitly in header and/or body - instead of the *.pch file. Then this error goes away in my case.

Also deleting the derived data workes once in a while. Did you change the location in preferences recently by any chance. I also got this error when I use a ramdisk for derived data and then go back to default. This is the most annoying case - since it causes this error to appear then in almost every file.

This error seems to happen more often in Xcode 4.4 than the prior versions.

bneely
  • 9,003
  • 4
  • 36
  • 46
user387184
  • 10,600
  • 12
  • 72
  • 141
  • I am using the pch file currently, but I'm likely to just remove it and add it as needed because it is super annoying. – rnystrom Aug 28 '12 at 12:31
2

Have you included the library files correctly? Take a look at that. Sometimes ARC issues might occur if we don't include the correct file, or something's missing or not connecting UI.

ЯegDwight
  • 23,615
  • 10
  • 43
  • 51
Preethi
  • 195
  • 1
  • 10
1

For me the issue was that I created UnityInterface.h/m file to handle the obj-c to c# interface. UnityInterface.h is already defined by Unity. I renamed my own UnityInterface to _UnityInterface and now everything works.

tonisives
  • 905
  • 9
  • 14
1

Just posting this for anyone who might have this problem later and doesn't find any of these solutions to work: If you have any pragma marked #if statements that only execute if the program is in debug mode it will obviously cause anything declared inside of them to not be declared when you try to archive/export.

Delimiter
  • 113
  • 7
0

I had the same problem. Closing and opening XCode didn't help.

I solved it by checking errors in other targets and fixing them (I had tons of errors in my unit testing target). Also I moved header links from h files to m files. But I'm pretty sure, that the first thing was critical.

Denis Kutlubaev
  • 13,009
  • 6
  • 76
  • 67
0

For others who experienced the same problem and tried all solution above with no result, perhaps you should try something like I did. I solved the problem simply by unplugging my iPhone USB cable from my Mac and then replugged again those cable. After that, rebuilt again and all undeclared identifier errors were gone.

yunhasnawa
  • 735
  • 10
  • 27
0

I had the same error. In my case, it was on this line of code:

- (void)playerItemDidReachEnd:(NSNotification *)notification {
      // some code
  }

My error message said:

Use of undeclared identifier 'playerItemDidReachEnd'

I tried added this line to the .h file:

- (void)playerItemDidReachEnd:(NSNotification *)notification;

I cleaned it, I re-booted my macbook, and I was still getting the error.

Finally, I decided to try to delete the line in the .h file. I then pasted it into a text file, and then copied and pasted it back in to the .h file.

Now I cleaned and VOILA' !!! no more errors. Go figure. This happens sometimes in VBA. Somehow there seems to be unseen formatting in a line of code. So I thought it might be happening with xCode. Cutting it out, pasting into a text file, cutting out of the text file, and pasting it back in right where it was - fixed it in my case.

---- UPDATE ----- The above was posted as my answer. Apologies, apparently there's something else wrong.

After cleaning - my ERRORS were gone. Now I tried to build and run my app. THE ERRORS CAME BACK! So this time I re-created the class files after cutting out all the text, and pasting it into a text file. I did it for both my .m and .h files. But now the errors are back again after trying to run. SORRY. I don't know how to delete this text altogether cuz it is not an answer.

Tried to build and run my app. THE ERRORS CAME BACK!

There was also an error msg that I was missing a bracket ( } ). Finally I looking at the method just before this method, and sure enought it was missing the ending bracket! That was it!

0

Might be little late in answering.

I had this issue very recently. I fix this by updating my OS and then updating Xcode. I tried updating Xcode alone but did not happen because Xcode 9.4 requires OS High Sierra 10.13.*

Happy Updating :)

Sdembla
  • 1,429
  • 11
  • 13
0

It it compile time error

Use of undeclared identifier '<class_name>'

I was run into this issue when developing own framework and app. Objective-C consumer -> Objective-C static framework

Report Navigator had a clear description

umbrella header for module '<module_name>' does not include header '<class_name>.h'

The solution was just to add #import <class_name>.h into umbrella header in a framework target

yoAlex5
  • 13,571
  • 5
  • 105
  • 98