Xcode build keeps failing due to Swift error

I am trying to get my project to build but I keep getting compile errors in one of the files that is provided by the Swift toolchain. The error is "Unknown type name 'NSCalendarIdentifier'" and it is in NSCalendarShims.h. I compared my file to the one on Github and they are exactly the same, I really don't know what is wrong. I am running Xcode 9.4.1 on MacOS Mojave Dev Beta. I've tried deleting Xcode and all it's dependencies as well as recloning my project and nothing works. I've also tried reverting to commits that previously worked but they all cause this same error. Thank you

Answered by QuinceyMorris in 321586022

It's likely an incompatibility with CocoaPods. Every time a new Swift version is released, people find that existing pods break. CocoaPods must be doing something a bit hinky that makes it dependent on the exact Swift version, in a very fragile way.


In most cases that we hear about here, people fix the problem by rebuilding all their pods. (Sorry, I don't use CocoaPods, so I've never been interested into looking into the problem to understand what's really going on.)

What does "one of the files that is provided by the Swift toolchain" mean? Swift doesn't really "provide" .h header files to your project, so something else is going on.


So let's to break it down. Where is the error appearing? On a source line in one of your .swift files? If so, what is the line? If you (for example) comment out that line, does the error appear somewhere else, or does it go away?


My guess is that "NSCalendarShims.h" is coming from debug information (so it reflects something that was processed when Swift was built but has no meaning now), or is referenced by a module definition.


Can you recreate the problem in a new project, using just a fragment of code from the file that has the error?


Sorry, I'm not sure what else to ask, at this point.

Hey, sorry for the late reply. The error is appearing in NSCalendarShims.h which I did not provide. The comments in the file say it is "part of the Swift.org open source project. Xcode will not let me edit that file so I can't comment anything out. It does say next to the error "In file included from <module-includes>:1:", but what does this mean? I'm using CocoaPods to manage dependencies. Thank you

Ok, this is weird. I tried adding the AdSupport.framwork file to my project and now the project builds successfully? I'd still like to know what is going on if anyone has insight 🙂

Accepted Answer

It's likely an incompatibility with CocoaPods. Every time a new Swift version is released, people find that existing pods break. CocoaPods must be doing something a bit hinky that makes it dependent on the exact Swift version, in a very fragile way.


In most cases that we hear about here, people fix the problem by rebuilding all their pods. (Sorry, I don't use CocoaPods, so I've never been interested into looking into the problem to understand what's really going on.)

I’ll give it a shot if it happens again. Thank you

Xcode build keeps failing due to Swift error
 
 
Q