CocoaPods和Swift 3.0

Gui*_*tro 21 ios cocoapods swift swift3 xcode8

我只是想在我的一个项目中尝试Swift 3.0.Xcode打开迁移窗口以更新我的项目以使用Swift 3.0.

问题是,我只是想更新我的项目,并保持Pods项目不变,因为在我pod install再次运行之后任何更改都将被丢弃.

任何人已经有解决方案吗?

JAL*_*JAL 28

你问的是不可能的.Xcode构建您的Cocoapods依赖项以及您的项目.你不能在同一个项目中混合使用Swift 2.x和Swift 3代码,或者使用Swift 3中使用Swift 3编写的Cocoapods.


小智 5

只需在您的 podfile 末尾使用以下命令,它就会设置您的 pods 文件,让框架自动采用 swift 3 编译器或遗留编译器,这样您就不会在 swift 3 中遇到 cannot use swift 2.1 和类似的错误。

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

使用这个,看看我的 podfile 的以下示例。只要确保结束语句不在我上面写的块之前。

platform :ios, '8.0'
use_frameworks!

target 'Project 1'

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end
Run Code Online (Sandbox Code Playgroud)