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

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


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


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    endend

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


Maybe you can clean the target before you build it.It works fine for me.