Whirlwind Whirlwind - 1 year ago 130
Swift Question

Updating pods (Charts) to the latest Swift syntax

Currently I am using Charts pod in my Objective-C project, so I had to open it today in Xcode 8.1 and of course, I got this message:


This wouldn't be a problem if it was my code, but we are talking here about pods. So, what would be the proper way to handle this warning and switch to Swift 3 syntax for this pod?

What I have tried:

I have run pod update command, and updated it hopefully to the latest version...Still, I am getting the same message when I open Xcode. This is my Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.2'
pod 'Charts', '~> 3.0'


target 'drivingCOACH' do
pod 'Charts', '~> 3.0'

Answer Source

The Charts pod is documented on https://cocoapods.org/pods/Charts. Current version (at the time of the question) is using Swift 3.0. So when using it, all your dependencies must be using Swift 3.0 too (you can't mix dependencies of different Swift versions when using Frameworks, which is currently a mandatory requirement).

You could manually change build settings to specify that each pod target is for Swift 3.0 (by setting "Use legacy Swift" value to NO). But because your project is in Objective-C, you may end up to do this operation each time you run pod install.

To avoid that trouble, you can extend the installation script of your Podfile to include those lines, and it will perform exactly the same as above on your next pod install:

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

Those lines won't be needed anymore the day you decide to integrate some Swift code to your app, because CocoaPods will then match the dependencies Swift version to what you are using.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download