I have a Swift Module that was fully migrated to Swift 5 using XCode version 10.2.1. When I 'distribute' the Module internally, I have no issues when integrating. When I distribute (using XCode's Organizer) the Module to another developer, they see the following error:
Module compiled with Swift 4.2.1 cannot be imported by the Swift 5.0.1
My internal applications all use Swift 5 as the build language. My XCode command line tools are version 10.2.1.
The other developer is also using Swift 5 with XCode 10.2.1.
What do I need to do to make my Module compile appropriately?
In most cases, this happens because the swift version of the module is not set correctly.
Before building the module, check the swift version of the module in Build Settings/Swift Language Version.
How is your module imported into your Xcode project? Are you using Carthage or Pod by any chance? If so, make sure your Terminal is pointing to the right XCode version prior to importing and installing your package locally via carthage or pod install.
Open a Terminal and check the selected XCode version:
/usr/bin/xcodebuild -version
If this is not the same version of XCode, make sure to point to the your current XCode app binary
sudo xcode-select -switch PATH_TO_YOUR_XCODE.APP
Import your package via carthage/pod, go back to your project in xcode, clean and build.
Existing project working in Xcode 9.3 and suddenly giving error in Openpay Framework while run in Xcode 10 (not beta version).
My swift version is 4.2, if i changed to Swift 4 or Swift 3 then also same error.
I have tried following things but not worked..
pod file update
clean and build project
delete derived data and clean-build project
quit xcode. open again, clean and build.
sudo xcode-select -switch /Applications/Xcode.app
carthage update --platform iOS --no-use-binaries
You are adding Openpay.frameworkin your project (using the link from their readme). The framework is built using Xcode 9.4 - you can check it in Info.plist file inside framework (just open it as folder). Here you have several options - ask them to release new version or do it yourself - looks like it is open source library, so you can clone it and build the framework yourself using Xcode 10
However I have recompiled the framework using the same Xcode and it still gives me this error.
Base SDK iOS 11.1 for both
Swift Language Version Swift 4.0 for both
Not using Pods/Carthage
I hope someone might know
Update:
For release versions of Xcode:
This error (and similar errors involving Swift 4.1, 4.2, etc.) will occur when opening a project with Xcode 9.1, 9.2, 9.3, 9.4, 10, etc. that uses frameworks that were built with earlier Xcode tools.
To fix the issue, update and rebuild your frameworks using Carthage ( carthage update --platform iOS), Cocoapods (pod update or pod install), or manually, with the new updated Xcode tools. The tools should be updated automatically when you update Xcode, but if not, you can follow the steps outlined below in the original answer.
You may also need to clean your project cmd + shift + k and possibly your build folder cmd + option + shift + k to get Xcode to not use cached framework builds.
In some cases you may also need to delete your derived data folder (Easily found by going to Xcode Preferences -> Locations -> Derived Data Folder
(Thanks Stunner)
For beta versions of Xcode:
See original answer below and then follow steps above.
Original Answer:
You probably still have your xcodebuild tools set to Xcode 9.0 which builds with Swift 4.0 and is incompatible with Xcode 9.1 beta's Swift 4.0.1.
Check in the terminal using the command:
xcodebuild -version
Or just go into Xcode preferences -> Locations and check/change the command line tools to Xcode 9.1. You should be set then.
My issue was due to an external framework not being compiled for Swift 4.0.2. I had added this file via Carthage, so running:
carthage update --platform iOS
And then cleaning the project cmd + shift + k and build folder cmd + option + shift + k and deleting the derived data folder (merely moving it to trash works as well) worked for me.
In my case, I downloaded xCode 11 Beta version to test SwiftUI. When i run my project, i got "Module compiled with Swift 5.1 cannot be imported by the Swift 5.0.1 compiler:..." error.
To do fix this issue. i changed xCode command line tool to new xCode 11 comment line tool. After that, you can create new xcode project with SwiftUI.
Xcode -> Preferences -> Location -> XCode command Line Tool
i hope, this will help someone who want to test with new freamework :)
Install Xcode Toolchain of specific Xcode version which was working for you from here.
An Xcode toolchain includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift.
Open Xcode's Preferences, navigate to Components > Toolchains , and select the installed Swift toolchain.
This will let you compile and run the app for now.
I hit this issue with Xcode 10 beta, which adds Swift 4.2. My issue was unrelated to Carthage or any external dependencies.
Go to YourTarget > Build Settings > Swift Language Version for all of your Xcode targets.
Mine were all set to Swift 4.
After adding a Copy Files Build Phase, I started getting the error
:0: error: module compiled with Swift 4.1.2 cannot be imported by the Swift 4.2 compiler: /Users/user/Library/Developer/Xcode/DerivedData/MyApp-faskfrihumfcdibjxisjvbfshppp/Build/Intermediates.noindex/MyApp.build/Debug/MyAppExtension.build/Objects-normal/x86_64/MyClass~partial.swiftmodule
Command MergeSwiftModule failed with a nonzero exit code
I then set each target's Swift Language Version to Swift 4.2, which eliminated the error.
I'm not sure why the error was occuring in the first place, though, as having all targets set to Swift 4 should be equally as valid.
In my case (Xcode 9.2):
I went to Xcode Preferences > Locations > Derived Data
I then deleted the data and did a clean build and was ok.
In my case, I used CocoaPods with plugin cocoapods-binary to prebuild libraries to binaries. After I upgrade Xcode from 10 to 11, Xcode gives me this error:
Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1 compiler
I fix it by removing the /Pods directory and running pod install.
In my case, I re-compiled the framework with whatever version it was complaining about.
To recompile, run pod update or update the carthage (which ever one you're using), and build the project.
Then search for the framework in finder. Copy-paste the theFramework.framework to your project and make sure to "Copy items if needed."Build the project again and it should work.
I created some frameworks on my own using Xcode 8.2.1 with Carthage package manager. When I try to use this framework in Xcode 8.3.3 I am getting the error below:
Module compiled with Swift 3.0.2 cannot be imported in Swift 3.1
I tried rebuilding the created framework using Xcode 8.3.3 and did carthage update in my existing project in which I am trying to use the framework. Still it throws the same error. Do I need to create the framework again using Xcode 8.3.3 in order to get rid of this error? Or is there a way to re-compile the existing framework?
The problem was my default Xcode selection path was set to Xcode 8.2.1.
So every time I built the framework using carthage build --no-skip-current, it was building with Xcode 8.2.1.
I changed my Xcode selection path to point to Xcode 8.3.3 by using the following command in Terminal:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Now the framework has been updated and I am able to access my framework in Xcode 8.3.3 without any issue.
I have just installed the xcode 8.0 and upgrade my project to swift 3. I was using swift 2.2 and xcode 7.3.1.
But getting following error:
Swift does not support the SDK 'iPhoneSimulator9.3.sdk'
Command
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
failed with exit code 1
This happened to me when I had simultaneously installed both Xcode 7 and 7.3 and after automatic update I was left with 8.0 only.
One indication that something got messed up was output of xcodebuild -sdk -version in terminal:
DVTSDK: Warning: SDK path collision for path '<DVTFilePath:0x7fd810db4c50:'/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS3.0.sdk'>': SDK with name 'watchos3.0' being superceded by SDK with 'watchos3.0'.
Solution:
Quit Xcode
go to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
remove the iPhoneOS9.3.sdk folder from that directory. Be sure to make an external copy if you still need it so you can put it back later.
restart Xcode, clean, and build
???
PROFIT
UPDATE:
According to #tsafrir comment, delete also 'iPhoneOS9.3.sdk' for simulator folder:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
The iPhoneOS9.3.sdk for the simulator is at Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs.
quit xcode
delete
clean
build again.
Not the best solution, but selecting - "Use Legacy Compiler Version": Yes, removed that warning for me.
It happen due to old xcode still in system and you updated new one.
For fixing this use following step.
Quit Xcode
go to
Simulator and iPhoneOS. platform
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
3. remove the iPhoneOS9.x.sdk folder from that directory. Be sure to
make an external copy if you still need it so you can put it back
later.
Copy old xcode sdk (iPhoneOS9.x(Updated SDK))
Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/ iPhoneOS9.3(Updated SDK)
5> Paste this SDK in new XCODE 8 in this folder
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
6> Clean and Build.
Fixed
Open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs