iOS 11 is about to get released, you want to test your app with Xcode9 and you will encounter this little (but important) problem: Not all pods will be Swift 4 on day 1 (or will ever be!)
In your private pods (or public pods that are open-source), you should add:
Pod::Spec.new do |s|
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.2' }
s.compiler_flags = '-swift-version 3.2'
end
Anybody importing those pods will get the correct Swift version out of the box, without any special thing on their part.
I wish I could just modify all podspecs, but I do not have that power. But that can be fixed in your Podfile, just make all your pods defaults to Swift 3.2
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
However, you may be like me, and split your apps with private pods (code reuse is good!), and you will probably convert those pods to Swift 4. And now you want to mix both types
Again, in your podfile, use this:
post_install do |installer|
['TargetName1','TargetName2','TargetName3'].each do |targetName|
targets = installer.pods_project.targets.select { |target| target.name == targetName }
target = targets[0]
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
end
end
You're done! Eventually, all your pods will have migrated to Swift4, and you can just go back to using CocoaPods normally