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

IosCocoapodsFacebook LoginXcode9 BetaSwift4

Ios Problem Overview


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 !

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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

Solution 3 - Ios

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

Solution 4 - Ios

I ran into the same issue on Xcode 9 Beta 3, which pointing to 'Alamofire' and tried a few different solutions, the easiest one i found is

1. CMD+SHIFT+K to clean the build
2. Restart Xcode 9 <-- make sure you do this step, that's critical. `

Solution 5 - Ios

Doing a "clean build folder" and restarting Xcode 9 cleaned up the error for me. Also the error didn't stop the app from running on my device or the simulator.

Solution 6 - Ios

goto xcode DerivedData directory then remove all file inside it and recompile your project . it work for me .

and default DerivedData directory is :~/Library/Developer/Xcode/DerivedData.

Solution 7 - Ios

If using Carthage , Open terminal and;

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

If using Pod , Open terminal and;

pod update

(Also if don't work in pod, you can change SWIFT_VERSION in podfile Ex:

config.build_settings['SWIFT_VERSION'] = '3.2'

)

After;

Open Xcode and use;

Command+Option+Shift+K

enter image description here

Solution 8 - Ios

It works for me.

1.Clean your project in Xcode 8

2.Build or run your project in Xcode 9

Solution 9 - Ios

I cleaned the project in Xcode 9, and then run the app, it works.

Solution 10 - Ios

I had the same problem with Xcode 9 GM and this solved my problem: Remove it from the project and drag it again into "Embedded Binaries".

Solution 11 - Ios

Clean Build Folder

Cmd + option + shift + K

Solution 12 - Ios

I have

pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'

in my project and import FBSDKLoginKit, after cleaning the target i didn't have any issue

Since the pod you are using is in swift and is a beta pod, it is likely that you would have some issues with the swift 4 compiler, you should use the objective-c version of the pod for the time being

Solution 13 - Ios

If you use from Pod:

  1. In Podfile comment FacebookLogin pod
  2. >pod install
  3. In Podfile uncomment FacebookLogin pod
  4. >pod install
  5. Run again your project

Solution 14 - Ios

For my case - the actual pod referenced a static zip with prebuilt binaries targeting swift 3.1. So only solution is to rebuild the framework with source from xcode 9.

https://github.com/AudioKit/AudioKit/issues/980

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
QuestionArnaudView Question on Stackoverflow
Solution 1 - Iosxavi.pedralsView Answer on Stackoverflow
Solution 2 - IosklingerView Answer on Stackoverflow
Solution 3 - IosTomorJMView Answer on Stackoverflow
Solution 4 - IosXu YinView Answer on Stackoverflow
Solution 5 - IosJohn PavleyView Answer on Stackoverflow
Solution 6 - IosrecoView Answer on Stackoverflow
Solution 7 - IosSwiftDeveloperView Answer on Stackoverflow
Solution 8 - IosRayJiangView Answer on Stackoverflow
Solution 9 - IosShan YeView Answer on Stackoverflow
Solution 10 - IosFrancisco PereiraView Answer on Stackoverflow
Solution 11 - IosVineesh TPView Answer on Stackoverflow
Solution 12 - Iosthibaut noahView Answer on Stackoverflow
Solution 13 - IosHamedView Answer on Stackoverflow
Solution 14 - IosjohndpopeView Answer on Stackoverflow