Xcode 9:无法在Swift 4.0中导入使用Swift 3.1编译的模块

时间:2021-12-07 19:16:39

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

在更新到Xcode 9之后,我尝试构建我的一个项目。

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

我使用FacebookLogin pod。我在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.

在我的目标的构建设置中,Swift语言版本被设置为Swift 3.2。

Xcode 9:无法在Swift 4.0中导入使用Swift 3.1编译的模块

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

我想我需要等Facebook更新他们的pod ?还有其他建议吗?

Thanks !

谢谢!

14 个解决方案

#1


63  

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:

我想补充一点,如果您正在使用Carthage编译Swift 3.2中的一个模块,那么您应该到一个终端运行:

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

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

要使用Xcode 9命令行工具,可以运行:

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:

要还原并使用稳定的Xcode命令行工具,只需运行:

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

#2


25  

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.

Xcode 9附带了一个理解Swift 3.2和Swift 4的Swift 4编译器,它甚至允许您在两个版本之间进行混合和匹配。不幸的是,不支持其他版本。

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

即使您将您的语言设置为Swift 3.2,它也使用Swift 4编译器。

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:

如果您正在使用cocoapods,您可以将这个添加到pod文件的末尾,以迫使pod使用Swift 3.2或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.

或者,您可以暂时将pod中的文件直接放入项目中,直到FacebookLogin更新为Swift 3.2或4。

Note: Edited based on Matt's feedback

注:根据马特的反馈进行编辑

#3


19  

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

也许您可以在构建目标之前清理它。对我来说很好。

#4


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.

执行“清理构建文件夹”并重新启动Xcode 9为我清除了错误。此外,这个错误并没有阻止应用程序在我的设备或模拟器上运行。

#5


10  

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

我在Xcode 9 Beta 3上遇到了同样的问题,它指向“Alamofire”,并尝试了几种不同的解决方案,我找到的最简单的解决方案是。

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

#6


8  

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

goto xcode DerivedData目录然后删除其中的所有文件并重新编译项目。这对我很有效。

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

默认的DerivedData目录是:~/Library/Developer/Xcode/DerivedData。

#7


4  

If using Carthage , Open terminal and;

若使用迦太基,则打开终端;

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

If using Pod , Open terminal and;

如使用Pod,则打开终端;

pod update

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

(如果不使用pod,也可以在podfile Ex中更改SWIFT_VERSION:

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

)

)

After;

后;

Open Xcode and use;

打开Xcode,使用;

Command+Option+Shift+K

Xcode 9:无法在Swift 4.0中导入使用Swift 3.1编译的模块

#8


3  

It works for me.

它适合我。

1.Clean your project in Xcode 8

1。在Xcode 8中清理项目

2.Build or run your project in Xcode 9

2。在Xcode 9中构建或运行项目

#9


3  

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

我在Xcode 9中清理了项目,然后运行应用程序,它工作了。

#10


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

我对Xcode 9 GM也有同样的问题,这解决了我的问题:将它从项目中删除,并再次将它拖放到“嵌入式二进制文件”中。

#11


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

在我的项目和导入FBSDKLoginKit中,在清理完目标后我没有任何问题

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

由于您正在使用的pod是在swift中,并且是beta pod,所以您可能会对swift 4编译器有一些问题,所以您应该暂时使用pod的objective-c版本

#12


0  

If you use from Pod:

如果您使用Pod:

  1. In Podfile comment FacebookLogin pod
  2. 在Podfile中评论FacebookLogin pod
  3. pod install

    圆荚体安装

  4. In Podfile uncomment FacebookLogin pod
  5. 在Podfile中取消对FacebookLogin pod的注释
  6. pod install

    圆荚体安装

  7. Run again your project
  8. 再次运行您的项目

#13


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.

对于我的案例——实际的pod引用了一个静态的zip文件,其中包含针对swift 3.1的预构建二进制文件。因此,唯一的解决方案是使用xcode 9的源代码重新构建框架。

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

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

#14


0  

Clean Build Folder

清洁建立文件夹

Cmd + option + shift + K

#1


63  

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:

我想补充一点,如果您正在使用Carthage编译Swift 3.2中的一个模块,那么您应该到一个终端运行:

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

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

要使用Xcode 9命令行工具,可以运行:

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:

要还原并使用稳定的Xcode命令行工具,只需运行:

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

#2


25  

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.

Xcode 9附带了一个理解Swift 3.2和Swift 4的Swift 4编译器,它甚至允许您在两个版本之间进行混合和匹配。不幸的是,不支持其他版本。

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

即使您将您的语言设置为Swift 3.2,它也使用Swift 4编译器。

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:

如果您正在使用cocoapods,您可以将这个添加到pod文件的末尾,以迫使pod使用Swift 3.2或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.

或者,您可以暂时将pod中的文件直接放入项目中,直到FacebookLogin更新为Swift 3.2或4。

Note: Edited based on Matt's feedback

注:根据马特的反馈进行编辑

#3


19  

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

也许您可以在构建目标之前清理它。对我来说很好。

#4


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.

执行“清理构建文件夹”并重新启动Xcode 9为我清除了错误。此外,这个错误并没有阻止应用程序在我的设备或模拟器上运行。

#5


10  

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

我在Xcode 9 Beta 3上遇到了同样的问题,它指向“Alamofire”,并尝试了几种不同的解决方案,我找到的最简单的解决方案是。

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

#6


8  

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

goto xcode DerivedData目录然后删除其中的所有文件并重新编译项目。这对我很有效。

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

默认的DerivedData目录是:~/Library/Developer/Xcode/DerivedData。

#7


4  

If using Carthage , Open terminal and;

若使用迦太基,则打开终端;

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

If using Pod , Open terminal and;

如使用Pod,则打开终端;

pod update

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

(如果不使用pod,也可以在podfile Ex中更改SWIFT_VERSION:

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

)

)

After;

后;

Open Xcode and use;

打开Xcode,使用;

Command+Option+Shift+K

Xcode 9:无法在Swift 4.0中导入使用Swift 3.1编译的模块

#8


3  

It works for me.

它适合我。

1.Clean your project in Xcode 8

1。在Xcode 8中清理项目

2.Build or run your project in Xcode 9

2。在Xcode 9中构建或运行项目

#9


3  

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

我在Xcode 9中清理了项目,然后运行应用程序,它工作了。

#10


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

我对Xcode 9 GM也有同样的问题,这解决了我的问题:将它从项目中删除,并再次将它拖放到“嵌入式二进制文件”中。

#11


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

在我的项目和导入FBSDKLoginKit中,在清理完目标后我没有任何问题

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

由于您正在使用的pod是在swift中,并且是beta pod,所以您可能会对swift 4编译器有一些问题,所以您应该暂时使用pod的objective-c版本

#12


0  

If you use from Pod:

如果您使用Pod:

  1. In Podfile comment FacebookLogin pod
  2. 在Podfile中评论FacebookLogin pod
  3. pod install

    圆荚体安装

  4. In Podfile uncomment FacebookLogin pod
  5. 在Podfile中取消对FacebookLogin pod的注释
  6. pod install

    圆荚体安装

  7. Run again your project
  8. 再次运行您的项目

#13


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.

对于我的案例——实际的pod引用了一个静态的zip文件,其中包含针对swift 3.1的预构建二进制文件。因此,唯一的解决方案是使用xcode 9的源代码重新构建框架。

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

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

#14


0  

Clean Build Folder

清洁建立文件夹

Cmd + option + shift + K