Xcode shows many errors but program compiles and runs fine (in both simulator and device)

XcodeCompiler Errors

Xcode Problem Overview


After installing the CocoaLumberjack' log compressor class I've been getting this annoying behavior: Xcode complains that there are many undeclared identifiers and gives me many errors (not warnings but errors with the red icon).

The thing is that I can compile and run my iPad app just fine but Xcode won't do any autocompletion. I tried cleaning the build folder (Product > option + Clean), and also deleting derived data. I've also rebooted to no avail.

As you can imagine this is a pain to work with. I did have this behavior happen before on a previous version of Xcode; it had something to do with stuff in my precompiled headers file but using the solution above would always fix it. I'm currently using Xcode 4.4 (4F250).

Sample error I'm getting:

Semantic Error: use of undeclared identifier 'DDTTYLogger'

The above happens even with classes that I wrote myself and that have not changed since installing the CocoaLumberjack compressor class.

Xcode Solutions


Solution 1 - Xcode

I finally solved this after MANY attempts using the following:

Remove the last #import from my Prefix.pch and build again. Errors would happen (obviously). Put the line back and build again. No errors would show and after 10 seconds or so, errors would come back again.

Repeat the above except instead of the last #import, remove the last TWO imports, then three, four, etc. I did this until I removed five imports and when I put them back and waited, Xcode stopped complaining.

Note that this didn't occur to me at all. I read this solution on a blog somewhere.

Weird bug...

Solution 2 - Xcode

Open build settings and set "Precompile Prefix Header" to "No", that solved my problem.

Kudos for: https://stackoverflow.com/a/7035492/936957

Solution 3 - Xcode

I've been running into these issues constantly on all the latest versions of Xcode, in both Objective-C and Swift.

I noticed today that I was getting the errors in one particular class file. I removed it from some extra targets it was in and the errors finally went away!

I think Xcode has some fundamental bugs with it's handling of multiple targets right now. My theory is that if the other target is not built, you will essentially see errors from that target. Anyway hope this helps someone.

Solution 4 - Xcode

Not bad, If you follow these Steps-

1-Clean Xcode(Cmd+Shif+K).

2- Clear Derived Data(Cmd+Shift+G).

Enter this path( ~/Library/Developer/Xcode/DerivedData/).

3- Quit and open again Xcode.

Solution 5 - Xcode

This problem can cause by setting "Target Membership" for some files are not the same.

Example:

A class XYZ put in file "a.swift" and it's used in file "b.swift". But "Target Membership" setting of "a.swift" is not the same "Target Membership" setting of b.swift.

Check "Target Membership" setting as below:

enter image description here

enter image description here

Solution 6 - Xcode

I was having issues with a library installed via cocoapods. Going to Build Settings and searching for 'Allow Non-modular Includes In Framework Modules' then setting it to Yes did the trick.

Solution 7 - Xcode

I had it on Xcode 10.1 when I accidentally pressed:

Cmd+Shift+U - ( build for Testing )

try Clean (Cmd+Shift+K) and then:

Cmd+Shift+R ( build for Running )

Solution 8 - Xcode

After update to Xcode 11, I met the same problem. I tried all the mentioned advices (cleaning folders, turning on/off different settings, restarting xCode), but nothing helped. Also, I have a big project in C, so, I'd like to keep using precompiled headers.

Finally I found that simple restart of Mac OS solves the problem! It's really weird behaviour, but I'm happy anyway that I found a solution – it's hard to code when lots of colourful error messages float around.

Solution 9 - Xcode

For me it helped cleanning the project. XCode->Product->Clean

Solution 10 - Xcode

I got the similar type of issue.

Alternate option to fix this is Open organizer and delete the derived data of your project or delete all the projects in organizer projects tab. It works fine..

Solution 11 - Xcode

I just had the same thing in Xcode 5.1.

I fixed it by making sure there were no blank lines between #import's

Solution 12 - Xcode

I have removed some extra spaces and extra lines from .pch file and it xcode stopped complaining

Solution 13 - Xcode

This happened to me as well, but cleaning didn't fix it. What did was quitting and reopening XCode. Afterwards, all the phantom errors were gone. For those wondering, the tabs you have open when you close will still be open when you reopen.

Solution 14 - Xcode

I had this issue recently. It can be remedied in some cases by deleting the ModuleCache folder inside DerivedData, along with the project folder in DerivedData. Note that Xcode must be quit before doing this.

Solution 15 - Xcode

Running on Xcode Version 10.1 (10B61), I set the build setting "Increase Sharing of Precompiled Headers" to NO. I was working in an .xcworkspace with many projects sharing the same frameworks, and no Objective-C bridging header (meaning I've added no obj-c code myself). I'm not sure when Xcode did away with .pch files by default, but I didn't have any of those in my project.

Xcode Build Settings: Increase Sharing of Precompiled Headers = NO

Solution 16 - Xcode

Open up a terminal and create a nice little function accessible via the command line...

nano ~/.bashrc

add (making the necessary substitutions between the pointy braces)

cycle() {
  git stash save "BACKUP"
  git checkout <<SOME OTHER BRANCH>>
  git branch -D $1
  xcodebuild -allowProvisioningUpdates -workspace <<YOUR WORKSPACE>>.xcworkspace -scheme <<YOUR SCHEME>> -configuration Release clean
  git checkout $1
}

^X and save it by following the prompts, then enter source ~/.bashrc to make it visible to the current terminal session.

Make sure your branch is pushed to origin, cause we're going to delete it :)

Call the function using cycle <<MY BRANCH>> (once it's run you might want to call git stash pop to restore any working copy changes)

Hope it works for you! Xcode, get on your game!

Solution 17 - Xcode

In my case (mixed objc/swift project) at least part of errors were caused by absence of imports for some used frameworks, e.g. "import UIKit". Project was compiled successfully because frameworks were anyway included in headers in Prefix.pch file. But errors were shown, for example about not finding method defined in UILabel extension, and yes, this extension was without "import UIKit". So I think these errors in most cases depends on Prefix.pch precompilation/updating. Touching Prefix.pch, cleaning, removing derived data, closing/opening XCode sometimes helps, but not always.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJulianView Question on Stackoverflow
Solution 1 - XcodeJulianView Answer on Stackoverflow
Solution 2 - XcodeYunus Nedim MehelView Answer on Stackoverflow
Solution 3 - XcodeBen BaronView Answer on Stackoverflow
Solution 4 - XcodeiDeveloperView Answer on Stackoverflow
Solution 5 - XcodealphaplusView Answer on Stackoverflow
Solution 6 - XcodeAdamView Answer on Stackoverflow
Solution 7 - XcodeAviram NetanelView Answer on Stackoverflow
Solution 8 - XcodeAivanF.View Answer on Stackoverflow
Solution 9 - Xcodeim-a-teapotView Answer on Stackoverflow
Solution 10 - XcodeRAJAView Answer on Stackoverflow
Solution 11 - XcodeLuke RhodesView Answer on Stackoverflow
Solution 12 - XcodeMehul ThakkarView Answer on Stackoverflow
Solution 13 - XcodeshoeView Answer on Stackoverflow
Solution 14 - XcodePranav KasettiView Answer on Stackoverflow
Solution 15 - XcodenteisslerView Answer on Stackoverflow
Solution 16 - XcodeTom HowardView Answer on Stackoverflow
Solution 17 - XcodeVladimirView Answer on Stackoverflow