Cocoapods: Compiler Version for Xcode 8

Created on 15 Jun 2016  Â·  6Comments  Â·  Source: CocoaPods/CocoaPods

What did you do?

Run pod install for a pod that uses swift 2.3

What did you expect to happen?

Install all pod dependencies correctly.

What happened instead?

The pod is installed but the compiler version setting is not respected and Xcode 8 defaults for Swift 3

CocoaPods Environment

Stack

   CocoaPods : 1.0.1
        Ruby : ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
    RubyGems : 2.0.14.1
        Host : Mac OS X 10.12 (16A201w)
       Xcode : 7.3.1 (7D1014)
         Git : git version 2.7.4 (Apple Git-66)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ fdeab0150c4f811dc33db08c74e66cb75b54697e

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.0
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.0.0
cocoapods-try         : 1.0.0

Podfile

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

use_frameworks!
target 'Concert Playlist' do
pod 'Onboard'
pod 'Localytics'
pod 'BuddyBuildSDK'
pod 'Doorbell'
pod 'Google/Analytics'
pod "LaunchKit"
pod "Branch"
pod 'Charts', :git => "https://github.com/opswhisperer/Charts.git", :branch => "xcode8_swift23"
pod "AFNetworking"
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
pod 'FBSDKLoginKit'
pod 'iRate'
pod 'GoogleConversionTracking'
pod 'UIBarButtonItem-Badge', :git => "https://github.com/mikeMTOL/UIBarButtonItem-Badge.git"
pod 'GoogleIDFASupport'
end

This project is using swift 2.3, if you install it, Xcode does not set the compiler version
pod 'Charts', :git => "https://github.com/opswhisperer/Charts.git", :branch => "xcode8_swift23"

defect

Most helpful comment

As a work around I did this

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

But it really should preserve whatever is in the framework if it is set

All 6 comments

As a work around I did this

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

But it really should preserve whatever is in the framework if it is set

I think we should generate the build setting with 2.3 by default and tell folks to use a post_install hook if they want to use 3.0 — possibly inferring from the app could also be a sensible thing to do before applying the default.

I don't think that it is feasible to add this to the podspec as there is no clear definition on what e.g. Swift 3.0 is until the stable version ships. So there really isn't a way for CP to determine if a certain Pod would actually build with whatever Swift version is currently being used.

@neonichu I'm not sure what this means: there is no clear definition on what e.g. Swift 3.0 is until the stable version ships. Isn't that rather irrelevant to CocoaPods? It just means whatever the Xcode 8 beta currently installed says it means. Ultimately, I guess I don't understand the reasoning for not exposing this setting in the podspec, as Xcode 8 will support both, and for at least the next year it's an official setting supported by Apple. Forcing users to use a post_install hook to set it one way or the other doesn't seem like a good long term solution.

There is currently a PR pulling the version from the targets - https://github.com/CocoaPods/CocoaPods/pull/5540

Hey guys, which version of Cocoapods do I need in order to not use this workaround - https://github.com/CocoaPods/CocoaPods/issues/5521#issuecomment-226328062? Is it specified/documented anywhere?

I'm still getting “Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly." errors for pods.

bundle exec pod --version
1.0.1

@tomaskraina That workaround is working for me with Cocoapods 1.0.1. My Podfile:

source 'https://github.com/CocoaPods/Specs.git'

use_frameworks!

target 'MyApp' do
  pod "MyPod", :path => "../"
end

target 'MyApp_Tests' do
  pod "MyPod", :path => "../"  
end

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
Was this page helpful?
0 / 5 - 0 ratings