Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 9 : Module compiled with Swift 3.1 cannot be imported in Swift 4.0

After updating to Xcode 9, I tried to build one of my projects.

I use the FacebookLogin pod. I have a compiler error in FacebookLogin/LoginButton.swift

@testable import FacebookCore ❌ Module compiled with Swift 3.1 cannot be imported in Swift 4.0 

In my target's build settings, the Swift language version is set to Swift 3.2.

Screenshot added

I guess I need to wait for Facebook to update their pod ? Or any other suggestion ?

Thanks !

like image 844
Arnaud Avatar asked Jun 06 '17 20:06

Arnaud


2 Answers

Update:

Solution also tested and working in Swift 5 and Xcode 11.

Original:

I would like to add that if you are using Carthage to compile a module in Swift 3.2 you should go to a terminal and run:

sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer 

To use the Xcode 9 command line tools, then you can run:

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

This will compile the library with your current command line tools, it can be a bit slow but now the project should build.

Note

To revert and use your stable Xcode command line tools simply run:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer 
like image 172
xavi.pedrals Avatar answered Oct 13 '22 06:10

xavi.pedrals


Xcode 9 comes with a Swift 4 compiler that understands both Swift 3.2 and swift 4, it even lets you mix and match between the 2 versions. Unfortunately, other versions aren't supported.

Even if you set your language to Swift 3.2, it uses the Swift 4 compiler.

If you're using cocoapods, you can add this to the end of your pod file to force the pods to use Swift 3.2 or 4.0:

post_install do |installer|     installer.pods_project.targets.each do |target|         target.build_configurations.each do |config|             config.build_settings['SWIFT_VERSION'] = '3.2'         end     end end 

Alternatively, you could put the files from the pod directly into your project temporarily, until FacebookLogin is updated to Swift 3.2 or 4.

Note: Edited based on Matt's feedback

like image 32
klinger Avatar answered Oct 13 '22 04:10

klinger