Xcode Errors in Source Editor

Here's a problem I was having recently. My project would build and run fine, but the source editor was showing errors.

Sometimes the errors wouldn't be there, sometimes they wouldn't. Sometimes they'd interfere with things like autocomplete, and it made working with the affected source files rather frustrating.

The problem was that the source file was used in more than one target, and one of the targets in a scheme other than the one I was using to develop the app had build settings that were causing the file to not build successfully.

In my case, I'd added some Swift source to the project, and configured the bridging header in my main target, but not in the UI Tests target. This is hard to discover, because there's no way that I can see to build that target directly from Xcode.

But there is an indirect way to get it to build, and it's probably a good idea to enable this anyway:


Pick "Manage Schemes..." in the dropdown that appears when you click on your project name in the picker on the Xcode toolbar, 

Napkin 16 11 19 6 42 38 AM

Now when you Analyze your project, you're analyzing not just the main target, but any other targets you select as well. This will show the build errors in Xcode and make it easy to go fix them.