Home > Enterprise >  How to handle phantom Xcode errors pertaining to cross-language interoperability?
How to handle phantom Xcode errors pertaining to cross-language interoperability?

Time:12-13

I have a Swift Xcode project that contains code written in C. The bridging-header file successfully exposes the public C headers to Swift and the project builds and runs fine. However, Xcode routinely displays compile errors (not warnings, but errors) that the C objects cannot be found in scope; but they obviously can because the project runs just fine. These errors are very annoying because Xcode always says the project has errors when it doesn't. Is there a way to silence these phantom errors or is there something that Xcode needs me to do to satisfy its compiler requirements? Cleaning the build folder and clearing the cache will sometimes work to silence them, until they reappear again on their own. I'm using Xcode 13.1.

CodePudding user response:

If cleaning the build folder and the project's derived data doesn't do it, like it didn't for me, force Xcode to reevaluate the imported headers by commenting them all out in the bridging-header file, running the app (which will fail), and then uncommenting them and running again.

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//
//#import "someHeaderFile.h"
//#import "anotherHeaderFile.h"
  • Related