Xcode “Use of undeclared identifier” errors, compi

2019-01-16 15:58发布

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?

10条回答
别忘想泡老子
2楼-- · 2019-01-16 16:18

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.

查看更多
虎瘦雄心在
3楼-- · 2019-01-16 16:18

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.

查看更多
Viruses.
4楼-- · 2019-01-16 16:25

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.

查看更多
戒情不戒烟
5楼-- · 2019-01-16 16:26

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 :)

查看更多
爷的心禁止访问
6楼-- · 2019-01-16 16:30

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!

查看更多
成全新的幸福
7楼-- · 2019-01-16 16:33

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.

查看更多
登录 后发表回答