80

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 !

2

14 Answers 14

73

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
10
  • 1
    I had the same error using Algolia framework, and build it with carthage and Xcode 9 command tool worked fine ! Thanks
    – vmeyer
    Aug 10, 2017 at 10:14
  • 3
    Worked for me using SwiftyJson. Thanks! Aug 12, 2017 at 18:22
  • 2
    Worked for me using Alamofire
    – pachun
    Sep 21, 2017 at 18:41
  • Hi @xaviPedrals, I need your help... Im trying to run that project "github.com/swiftingio/SingTest" but getting that error "Module compiled with Swift 3.1 cannot be imported by the Swift 4.2.1 compiler: /Users/aliapple/Desktop/SingTestByAhtazaz/Pods/AudioKit/iOS/AudioKit.framework/Modules/AudioKit.swiftmodule/arm64.swiftmodule". Can you help me in this?
    – Ahtazaz
    Jun 17, 2019 at 9:53
  • Hi @Mr.Ahtazaz that project is from 2 years ago so probably it was made and compiled in Swift 3, first the project should be updated to Swift 4 or 5, then try running the carthage command carthage update NameOfTheLibrary --platform iOS --no-use-binaries to update the libraries and you should be okay Jun 17, 2019 at 10:32
26

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

1
  • 1
    FYI - This is somewhat overly aggressive by forcing all pods to Swift 4.0. If a pod is Swift 3 compliant, you can safely bump to Swift 3.2. Bumping to 4.0 will more than likely cause compiler issues for many pods.
    – Matt S.
    Jul 10, 2017 at 4:47
19

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

1
  • 7
    Didn't work for me, still looking for another solution.
    – Arnaud
    Jun 7, 2017 at 9:37
11

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. `
1
  • 11
    It's 2017 and we still need to restart Xcode to solve bugs. Thank you, Apple. Thank you.
    – Oded Harth
    Oct 5, 2017 at 21:59
10

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.

1
  • 1
    "clean build folder": To access the option open the Product menu and use the Option key to show the Clean Build Folder option.
    – Hans
    Aug 18, 2017 at 11:30
8

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.

8

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

5
  • 1
    Please don't post identical answers to multiple questions. Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, tailor your answers to the question. See meta.stackexchange.com/q/104227/311792
    – Papershine
    Sep 14, 2017 at 11:40
  • @paper1111 I explain everything in my answer and works Sep 14, 2017 at 11:42
  • I'm using carthage and this is the solution that worked for me. carthage update "My Framework" did not cut it. I had to update the entire carthage catalogue. Took forever but did the trick. Sep 24, 2017 at 7:22
  • 1
    This solution also worked for me. To be double sure make sure you close and relaunch xcode after cleaning the build folder with Command+Option+Shift+K. Oct 18, 2017 at 18:10
  • @SwiftDeveloper Where does the config.build_settings portion go?
    – Adrian
    Sep 29, 2018 at 23:15
4

It works for me.

1.Clean your project in Xcode 8

2.Build or run your project in Xcode 9

3

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

2

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".

1
  • I had the issue with Alamofire 4.5.1 and tried everything else on this page via pod update but without result. In the end I added the framework directly to my project and added it to my Embedded Binaries which worked
    – Heki
    Nov 1, 2017 at 6:48
2

Clean Build Folder

Cmd + option + shift + K
1

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

0

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
0

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

3
  • I have a similar issue with AudioKit being referenced inside pods. However, your solution refers to a build_frameworks.sh found in the 'Framework' Please add more details. I cannot find such a file.
    – TomV
    Oct 2, 2017 at 13:50
  • try to point the podfile to a newer release. a version that's been built with latest xcode 9 - / no build script changes needed. github.com/AudioKit/AudioKit/releases
    – johndpope
    Oct 3, 2017 at 16:12
  • Thanks for the tip. I had to update the AudioKit version in cocoapods to the latest one, which had the build_frameworks.sh. The build_frameworks.sh was needed to 'validate' AudioKit, to stop Apple rejecting the app.
    – TomV
    Oct 4, 2017 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.