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

Arn*_*aud 78 ios facebook-login cocoapods swift4 xcode9-beta

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

我使用FacebookLogin pod.我在FacebookLogin/LoginButton.swift中有编译器错误

@testable import FacebookCore
? Module compiled with Swift 3.1 cannot be imported in Swift 4.0
Run Code Online (Sandbox Code Playgroud)

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

截图添加

我想我需要等待Facebook更新他们的pod?还是其他任何建议?

谢谢 !

xav*_*als 72

更新:

解决方案还在Swift 4.2和Xcode 10中进行了测试和工作.

原版的:

我想补充一点,如果您使用Carthage在Swift 3.2中编译模块,您应该去终端并运行:

sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer
Run Code Online (Sandbox Code Playgroud)

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

carthage update NameOfTheLibrary --platform iOS --no-use-binaries
Run Code Online (Sandbox Code Playgroud)

这将使用您当前的命令行工具编译库,它可能有点慢,但现在应该构建项目.

注意

要恢复和使用稳定的Xcode命令行工具,只需运行:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Run Code Online (Sandbox Code Playgroud)

  • 使用SwiftyJson为我工作.谢谢! (3认同)
  • 使用Alamofire为我工作 (2认同)

kli*_*ger 26

Xcode 9附带一个Swift 4编译器,可以理解Swift 3.2和swift 4,它甚至可以让你在两个版本之间进行混合和匹配.不幸的是,不支持其他版本.

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

如果你正在使用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
Run Code Online (Sandbox Code Playgroud)

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

注意:根据Matt的反馈进行编辑


Tom*_*rJM 19

也许你可以在构建之前清理目标.这对我来说可以.

  • 没有为我工作,仍在寻找另一种解决方案. (7认同)

Xu *_*Yin 11

我在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. `
Run Code Online (Sandbox Code Playgroud)

  • 这是2017年,我们仍然需要重新启动Xcode以解决错误.谢谢你,Apple.谢谢. (11认同)

Joh*_*ley 10

做一个"干净的构建文件夹"并重新启动Xcode 9为我清除了错误.此错误也没有阻止应用程序在我的设备或模拟器上运行.


rec*_*eco 8

goto xcode DerivedData目录然后删除其中的所有文件并重新编译您的项目.它对我有用.

默认的DerivedData目录是:〜/ Library/Developer/Xcode/DerivedData.


Swi*_*per 8

如果使用Carthage,打开终端和;

carthage update --platform iOS --no-use-binaries
Run Code Online (Sandbox Code Playgroud)

如果使用Pod,打开终端和;

pod update
Run Code Online (Sandbox Code Playgroud)

(如果在pod中不起作用,您可以在podfile Ex中更改SWIFT_VERSION:

config.build_settings['SWIFT_VERSION'] = '3.2'
Run Code Online (Sandbox Code Playgroud)

)

后;

打开Xcode并使用;

Command+Option+Shift+K
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述