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

Viewed 14170

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.

17 Answers

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.

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

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 )

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.

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.

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.

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

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!

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.

Related