Quantcast
Channel: Nelson 寫些 iOS 開發的東東
Viewing all articles
Browse latest Browse all 20

如何為各個 Pod 指定 Swift 版本

$
0
0

最近升上 Swift 4.2,發現我用到的 Pods 有些還沒支援 4.2 導致編譯錯誤。解決方法也很簡單,只要指定每個 Pod target 的 SWIFT_VERSION4.0即可。

但是我們不能手動在 Xcode 裡頭調整,因為 CocoaPods 會把 Pods 的 SWIFT_VERSION設為跟你的 project 一樣,所以下次 pod install又會被改掉。

我們可以在 Podfilepost_install來自動修改,只要在 Podfile結尾加入以下片段即可。

post_install do |installer|
  installer.pods_project.targets.each do |target|
      # 我們也可以懶惰不用 if,讓所有 pod 的版本都設為一樣的
      if ['RxSwift', 'RxSwiftExt', 'RxCocoa', 'RxDataSources', 'ProtocolBuffers-Swift'].include? target.name
          target.build_configurations.each do |config|
              config.build_settings['SWIFT_VERSION'] = '4.0'
          end
      end
  end
end

參考來源:https://stackoverflow.com/a/46690240


Viewing all articles
Browse latest Browse all 20