Fix Swift Framework Error: Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.4 compiler:

Chances are you upgraded to the latest Xcode and along with it, your Swift compiler is updated as well. Then existing projects using a particular project have stopped working with similar error such as.

Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.4 compiler:

/Users/PauloOrquilo/Documents/Development/Mobile/Training/CoreData/Sync/iOSDemo/Carthage/Build/iOS/Sync.framework/Modules/Sync.swiftmodule/x86_64.swiftmodule

Or you are checking out some hosted on code on Github using some framework, the framework might have been built using an older compiler version, if you try to run the associated .xcodeproj or .xworkspace it won’t build the project.

This is only for frameworks built using Carthage. I haven’t experienced this on CocoaPods. Make sure you have Carthage installed – check this documentation on how to install Carthage – https://github.com/Carthage/Carthage

To fix, take a backup of your project, or better yet make sure you are using version control. Delete the framework that is failing from your project.

Go to the Project directory from the Terminal and make sure the Cartfile is available and run. Choose the right platform for the app.

carthage update --platform IOS

It should create a newly .framework on the Carthage/Build folder.

On Xcode go the General Tab and under Framework, Libraries and Embedded Content. Drag and drop the files

Then finally, try running the build and your project should be working.

Hope you find this tip useful.

Leave a Reply

Your email address will not be published. Required fields are marked *