Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a xcode 9 project with Swift 4.0 using Pods in Swift 3?

I want the main module of my iOS App to compile Swift 4.0 while the CocoaPods module compiles swift 3.

PS: Using Xcode 9 beta 2.

like image 492
Sanf0rd Avatar asked Jul 19 '17 18:07

Sanf0rd


2 Answers

If you are using some pods written in Swift 4, but some are Swift 3.2, here is the way you can specify the SWIFT_VERSION value for them:

swift_32 = ['Pod1', 'Pod2', 'Pod3'] # if these pods are in Swift 3.2
swift4 = ['Pod4', 'Pod5', 'Pod6'] # if these pods are in Swift 4

post_install do |installer|

    installer.pods_project.targets.each do |target|
        swift_version = nil

        if swift_32.include?(target.name)
            swift_version = '3.2'
        end

        if swift4.include?(target.name)
            swift_version = '4.0'
        end

        if swift_version
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = swift_version
            end
        end

    end

end
like image 126
bubuxu Avatar answered Oct 22 '22 15:10

bubuxu


Finally I got it to work: All I had to do was to put this script in the end of Podfile:

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
like image 38
Sanf0rd Avatar answered Oct 22 '22 15:10

Sanf0rd