The Pragmatic Ball boy

iOSを中心にやってる万年球拾いの老害エンジニアメモ

既存のプロジェクトでSwift2.3のままXcode8でビルドを通す

Xcode8でビルドするとデフォルトではSwift3でコンパイルされてしまいます。 とりあえずXcode8にあげるけどSwift2.3のままにしておいて、Swift3対応は後でという場合の対処方法です。

Build Settings

Build Settingsの"Use Legacy Swift Language Version"を"Yes"にする

  • f:id:yanamura:20160830183604p:plain

Cocoapodsの変更

Podfileの一番最後に以下を追加

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '2.3'
    end
  end
end

ライブラリをXcode8&Swift2.3対応のブランチを指定するようにする

Swift2.3とSwift3ではバイナリ互換がないので、ライブラリも含めてSwift2.3でコンパイルする必要があります

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire', :branch => 'swift2.3'
pod 'Realm', :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master', :submodules => true
pod 'RealmSwift', :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master', :submodules => true