Module compiled with swift 3.0 cannot be imported in Swift 3.0.1

SwiftSwifty Json

Swift Problem Overview


I upgraded Xcode to 8.1 GM and am now getting the below error for SwiftyJSON. Other imported frameworks seem to work. Is there a way to force this to work in Swift 3 until SwiftyJSON upgrades their framework? I used Carthage to import/update frameworks. I also tried changing Use Legacy Swift language version On and Off to no avail.

> Module compiled with Swift 3.0 cannot be imported in Swift 3.0.1: > Modules/SwiftyJSON.swiftmodule/arm64.swiftmodule

Swift Solutions


Solution 1 - Swift

SwiftyJson is being downloaded precompiled by carthage. The precompiled download is with Swift Version 3.0. That makes the compiler complain that the version is not correct. Using the following command:

carthage update --platform iOS --no-use-binaries

SwiftyJson (and all other frameworks within Carthage) will be compiled locally using the local version of Swift (3.0.1) and the compiler will not complain anymore.

Solution 2 - Swift

Remove the app chache from DerivedData, and rebuild. the error may be fixed.

The DerivedData path like this:

~/Library/Developer/Xcode/DerivedData/

Solution 3 - Swift

Make sure you've placed the new XCode 8.1 GM package in your Applications folder. We ran into this issue when one of us was running Carthage to update our dependencies, but had not replaced the XCode old 8.0 application in the applications folder (8.1 GM was running off the Desktop).

You want to make sure that when you run the following in terminal: xcrun swift -version that it returns Apple Swift version 3.0.1.

Solution 4 - Swift

Updating default Xcode to new one on terminal worked for me.

Step 1 : Use following command to update Xcode version to latest on Terminal. Ref

sudo xcode-select -switch <path/to/>Xcode.app

Step 2 : Now try carthage update command

carthage update --platform iOS

Solution 5 - Swift

Just to give the latest updates:

Carthage has released version 0.20 on Feb 27, 2017.

Carthage now only uses the pre-build binary if available pre-build binary is compatible.

That is being said, you no longer have to use: --no-use-binaries to avoid incompatible pre-build framework.

So make sure that you have carthage version greater than 0.20 and simply do:

carthage update --platform iOS

Solution 6 - Swift

Just like @zirinisp said:

  1. You can Using the following command:carthage update --platform iOS --no-use-binaries
  2. Using the following command:xcrun swift -version to see the Swift version
  3. Do this: Xcode->preferences->locations to clear the derived data and archives data, the most important to change the command line tools to "Xcode 8.1"
  4. Using the following command:xcrun swift -version,you can see the swift version is 3.0.1
  5. Set Use Legacy Swift Language Version = NO

I hope it will help you

Solution 7 - Swift

  1. Move the beta/GM version if the Xcode to /Applications folder and name it Xcode-beta

  2. Check the output of:

    xcrun swift --version

by running this command in terminal, its output should match with the swift version you want the app to compile, because Carthage uses output of this command, to determine the local Swift version.

  1. Update Xcode version to latest on Terminal by running following command:

    sudo xcode-select -s /Applications/Xcode-beta.app/

  2. Build the libraries for iOS and prevents Carthage from downloading existing (yet incompatible) precompiled binaries, by running following command:

    carthage update --platform iOS --no-use-binaries

  3. Clean & Build

Solution 8 - Swift

I had exactly the same issue with the library XCTest_Gherkin, what it worked for me was:

  1. Product -> Scheme -> XCTest-Gherkin
  2. Product -> Build

Hope it helps. I am using Cocoapods.

Solution 9 - Swift

In Xcode Build Settings make sure your Framework Search Paths contain the appropriate Carthage Build folder:

$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHH887View Question on Stackoverflow
Solution 1 - SwiftzirinispView Answer on Stackoverflow
Solution 2 - Swifti-chouView Answer on Stackoverflow
Solution 3 - SwiftClay GarrettView Answer on Stackoverflow
Solution 4 - SwiftMohammad Zaid PathanView Answer on Stackoverflow
Solution 5 - SwiftkanekinView Answer on Stackoverflow
Solution 6 - SwiftkrisView Answer on Stackoverflow
Solution 7 - SwiftTulView Answer on Stackoverflow
Solution 8 - SwiftAlan SteimanView Answer on Stackoverflow
Solution 9 - SwiftJohn CromieView Answer on Stackoverflow