0

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:

warning

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'

use_frameworks!

target 'drivingCOACH' do
  pod 'Charts', '~> 3.0'
end
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
  • Putting this in the end of your Podfile should solve the problem 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 – Thomas G. Nov 26 '16 at 13:51
  • @ThomasG. Well what this actually does ? Because I have another pods which works fine... – Whirlwind Nov 26 '16 at 13:52
  • Well, I ended up with changing Build Settings -> Use Legacy Swift version = NO. Also tried your code, and it worked. Still, I am not completely clear what it does ( It looks like it loops through all targets and sets their configs to use SWIFT_VERSION = 3, right? ) – Whirlwind Nov 26 '16 at 14:09
  • you are right. i can´t explain you the exactly reason why we need this lines for all pod targets have the same SWIFT_VERSION. Maybe this will be fixed in a later Cocoapods version. - one hint: watch out the Use Legacy Swift version flag because it will be reset after every pod install or update – Thomas G. Nov 26 '16 at 14:35
  • @ThomasG. Yeah, I have noticed what is happening after every update (or install) , thanks for pointing that thought. – Whirlwind Nov 26 '16 at 14:37

1 Answers1

1

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 deintegrate && 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'
        end
    end
end

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.

Also, you may need to delete your Derived Data folder (~/Library/Developer/Xcode/DerivedData by default) while Xcode is closed if you face some cache issues.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Still I don't know if this gone well... I have reinstalled Charts pod, but still I get a bunch of syntax errors (eg. In Swift 3 you have to use this and that...) Is this expected ? I thought if I re-install the pod, that it will be updated to the latest syntax... – Whirlwind Nov 26 '16 at 15:24
  • @Whirlwind are you on latest stable version of CocoaPods? `pod --version` should return `1.1.1` today. – Cœur Nov 26 '16 at 15:35
  • @Whirlwind oh, also, delete derived data while Xcode is closed – Cœur Nov 26 '16 at 15:36
  • @Whirlwind, last but not least, the [issue tracker](https://github.com/CocoaPods/CocoaPods/issues) is the best place for CocoaPods help. But they will often ask for a sample project that can reproduce the issue. – Cœur Nov 26 '16 at 15:41
  • Well, can't do that. But I can play with derived data thing...Which I somehow don't see anymore since Xcode 7.3.1. There was a Projects option in Window menu, right? I can't see that anymore. – Whirlwind Nov 26 '16 at 15:42
  • Yeah, no cleaning derived data manually : http://stackoverflow.com/a/38043112/3402095 – Whirlwind Nov 26 '16 at 15:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129109/discussion-between-whirlwind-and-coeur). – Whirlwind Nov 26 '16 at 15:55
  • @Whirlwind I forgot to mention you need to call `pod deintegrate` before `pod install`. I've edited the answer. – Cœur Nov 26 '16 at 16:39
  • I did that already. No luck. It just complains about some missing selectors and initializers from few classes – Whirlwind Nov 26 '16 at 16:41