87

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

Tejas
  • 1,050
  • 12
  • 23
HH887
  • 923
  • 1
  • 7
  • 14

9 Answers9

171

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.

zirinisp
  • 9,971
  • 5
  • 32
  • 38
  • 24
    You are welcome. To be honest carthage should be a bit more intelligent and check swift version number. – zirinisp Nov 02 '16 at 08:39
  • Any other ideas? Because this did not worked for me, although in my case I am having problems with Unbox – Xernox Nov 02 '16 at 10:45
  • This was excellent. Is there a way to embed this in the `Cartfile` so that I can just type `carthage update` without fellow developers needing to know/worry about the extra flags? – Craig Otis Nov 05 '16 at 16:45
  • I think that you cannot embed it. You can probably add it to fastlane, but i have not tried. – zirinisp Nov 07 '16 at 10:34
  • 1
    I had similar error with PromiseKit 4.0 after updating from to XCode 8.0 to XCode 8.1 I was having an EXC_BAD_ACCESS error. In the end, PromiseKit had to be recompiled with swift 3.0.1 and problem was solved. – Ricardo Anjos Nov 17 '16 at 09:24
  • Excuse me but where should I type this command Line ? From Terminal inside the Xcode folder ? I got a 'bash: carthage: command not found' @zirinisp – Jibeee Jan 18 '17 at 18:24
  • @Jibeee first install carthage brew install carthage , if it gives command not found install brew – yoshiiiiiiii Mar 22 '17 at 09:46
21

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

The DerivedData path like this:

~/Library/Developer/Xcode/DerivedData/
i-chou
  • 351
  • 2
  • 10
10

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.

Clay Garrett
  • 1,023
  • 8
  • 11
  • This worked for me, thank you! Also the command that worked in terminal was xcrun swift -version – HH887 Oct 26 '16 at 11:53
  • 2
    Still getting the same issue. Any other suggestions – harsh_v Oct 26 '16 at 12:56
  • Correction, I am as well. Built it fine the first go around and now getting the error again when trying to run it. – HH887 Oct 26 '16 at 13:38
  • 2
    This command worked for me: carthage update --platform iOS --no-use-binaries – HH887 Oct 26 '16 at 16:40
  • @HH887 - Thanks a bunch - that worked for me as well as it prevents the use of pre-built binaries that may have been compiled with a previous version of Swift. – Kevin Oct 29 '16 at 03:29
  • 2
    I've done `carthage update --platform iOS --no-use-binaries` and it still doesn't work. I've cleaned my project and restarted Xcode and I still get the error. Anything else I can try? – Clifton Labrum Nov 01 '16 at 07:17
  • @CliftonLabrum What happens when you run `xcrun swift -version` in terminal from your project directory. – Clay Garrett Nov 01 '16 at 15:44
  • 1
    I tried that. It returns `Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1) Target: x86_64-apple-macosx10.9` – Clifton Labrum Nov 01 '16 at 17:50
9

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
Community
  • 1
  • 1
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
9

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
kanekin
  • 91
  • 1
  • 3
  • XCode 8.3.3 After updating Carthage to 0.25 version and after doing below, it worked for me carthage update --platform iOS --no-use-binaries – anoop4real Sep 09 '17 at 07:33
  • @anoop4real It does not work for you without `--no-use-binaries`? Carthage should be able to detect if the binary is compatible with your compiler version. If not compatible, it's supposed to automatically drop the downloaded binary and build the framework locally. – kanekin Sep 12 '17 at 12:39
5

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

Bojan B
  • 2,091
  • 4
  • 18
  • 26
kris
  • 51
  • 3
1
  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

Community
  • 1
  • 1
Tul
  • 159
  • 1
  • 10
0

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.

Alan Steiman
  • 412
  • 1
  • 4
  • 14
0

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

$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS
John Cromie
  • 181
  • 2
  • 4