Module compiled with swift 3.0 cannot be imported in Swift 3.0.1 - swift

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

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.

Remove the app chache from DerivedData, and rebuild. the error may be fixed.
The DerivedData path like this:
~/Library/Developer/Xcode/DerivedData/

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.

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

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

Just like #zirinisp said:
You can Using the following command:carthage update --platform iOS --no-use-binaries
Using the following command:xcrun swift -version to see the Swift version
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"
Using the following command:xcrun swift -version,you can see the swift version is 3.0.1
Set Use Legacy Swift Language Version = NO
I hope it will help you

Move the beta/GM version if the Xcode to /Applications folder and name it Xcode-beta
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.
Update Xcode version to latest on Terminal by running following command:
sudo xcode-select -s /Applications/Xcode-beta.app/
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
Clean & Build

I had exactly the same issue with the library XCTest_Gherkin, what it worked for me was:
Product -> Scheme -> XCTest-Gherkin
Product -> Build
Hope it helps. I am using Cocoapods.

In Xcode Build Settings make sure your Framework Search Paths contain the appropriate Carthage Build folder:
$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS

Related

Swift 3.1.1 compile error: unknown key 'SwiftImportAsNonGeneric'

Some time after upgrading to Xcode 9, I discovered that I was no longer able to build a Kitura-based project with the Swift 3.1.1 snapshot (which I have installed via swiftenv).
When I ran swift build, some time into the build I would get:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes:8:28: error: unknown key 'SwiftImportAsNonGeneric'
SwiftImportAsNonGeneric: true
^
<unknown>:0: error: could not build Objective-C module 'Foundation'
It seems that there is a dependency between Swift and Xcode, and Xcode 9 is no longer fully compatible with Swift 3.1.1 (or earlier) snapshots. I believe it may be because my project uses Foundation, and Foundation on Mac is provided as part of Xcode, whereas on Linux it is part of the Swift snapshot (via swift-corelibs-foundation).
I did find a solution to this problem: If I keep a copy of Xcode 8.3.3 around (eg. in /Applications/Xcode8.3.3.app) then I can use sudo xcode-select -s /Applications/Xcode<version>.app/Contents/Developer to select the appropriate one prior to building with SPM, and I can then build both Swift 3.1.1 and 4.0 projects on the same system.
However, this feels a bit clunky. Each time I build a project with the 'other' Swift version, I have to make sure I run xcode-select, or the build will fail. Is having multiple versions of Xcode the right solution in this case, or am I missing a trick with Xcode 9?
note that if, like me, you upgraded Xcode via the App Store, previous versions of Xcode are still available from https://developer.apple.com/download/more/

Module compiled with swift 4.0 cannot be imported in swift 3.1 — Carthage

I wanted to test my app using Xcode 9 beta. Now I am back to Xcode 8 and I have the following error:
Module compiled with swift 4.0 cannot be imported in swift 3.1
To solve this error I refresh all Carthage build and made some cleaning:
removed all Carthage build and checkout
removed Derived Data directory
cleaned the project
run carthage update
But the error still here.
Carthage
The command used is: 'carthage update --platform iOS'
As the problem lie on always the same framework, DeviceKit I then manage to remove it from Cartfile.
Project build then show errors as DeviceKit is not found.
I then re-add it to Cartfile and run carthage update DeviceKit --platform iOS --no-use-binaries
And the error re-appear.
This related question bring answer but for Cocoapods: Module compiled with swift 4.0 cannot be imported in swift 3.1
Solved by the following steps:
delete some Derived Data for Carthage: rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
delete the Carthage folder for your project
Update Carthage: carthage update --platform iOS
I found the answer on the dedicated Carthage' page on GitHub: https://github.com/Carthage/Carthage/issues/2062

How to update the version of compiled framework

I am using XCode 8.3 and I am trying to Run my project which is connected with link and now I have a XCode Error: Module compiled with Swift 3.0.2 cannot be imported in Swift 3.1
So my question is how to update the version of the framework?
I downloaded this framework from the link that I've posted above.
I think that you need to update CocoaPods to a newer version supports XCode 8 (CocoaPods 1.1.0 or newer):
sudo gem install cocoapods
Then do a pod update to fix your dependencies that are not linking:
pod update
Delete the DerivedData folder for your project and rebuild, the link error should be gone.

Module compiled with Swift 3.0.1 cannot be imported in Swift 3.0 on BuddyBuild

I use BuddyBuild for a swift project with Xcode 8.0 and with Carthage 0.18.
Although, in logs I can see that all frameworks are cloning, checking out and building, I receive this one:
module compiled with Swift 3.0.1 cannot be imported in Swift 3.0: /tmp/sandbox/workspace/Carthage/Build/iOS/RealmSwift.framework/Modules/RealmSwift.swiftmodule/x86_64.swiftmodule
This is the entry in Cartfile for Realm:
github "realm/realm-cocoa"
Locally, everything builds, but with other configurations:
Xcode 8.1 and Carthage 0.18
This Module compiled with swift 3.0 cannot be imported in Swift 3.0.1 did not help me much, because of BuddyBuild.
EDIT
I can see that in logs:
Downloading realm-cocoa.framework binary at "v2.1.0"
after that, no building for realm.
Buddybuild typically run the carthage command with --no-build to make sure you don't experience with kind of error.
Note that buddybuild won't run the carthage command if you check in your Carthage/ folder.
You can find more information about how buddybuild deals with Carthage in our documentation.

Swift 3 CocoaPod does not pass lint

I’m upgrading a CocoaPod to Swift 3. It compiles and runs just fine, but pod lib lint fails with numerous compiler errors, because the linter tries to compile everything as Swift 2.3.
Attempts to set SWIFT_VERSION in the podspec or change “Use Legacy Swift Language Version” in my framework’s Xcode project do not solve the issue.
How do I make the pod linter use Swift 3?
It turns out CocoaPods now looks for a .swift-version file, as of 1.1.0.rc.2 (changelog). If the file contains 3.0, linting will work:
echo 3.0 > .swift-version
First you have to update cocoapods to 1.1.0.rc.2 by
[sudo] gem install cocoapods --pre
then as Paul Cantrell says, do
echo 3.0 > .swift-version
in the same dir where the pod spec is
I have this issue when develop SDK which is depending on socket.io-Client-Swift.
After type
echo 3.0 > .swift-version
still don't fix my problem.
However, I noticed pod lint use xcodebuild to test whether the framework is ready to be release without error.
Make sure you use Xcode8 to build pod lint. For some reason, I install both Xcode7 & Xcode8 and changed my xcodebuild path to xcode7, so the lint won't be pass when I want to make a framework with swift 3.
use the following code to make sure your xcode setting is right.
xcode-select -print-path
if the xcode-select path is not point to xcode8, you should using
xcode-select -switch <path>
set the xcode-select path to xcode8 which is usually in your Applications.
I know this was written for Swift 3, but you can do the same to update pods for 4.0:
echo 4.0 > .swift-version
This was done with version 1.3.1 of Cocoapods.