Cocoapods 指定三方库的swift版本

由于Xcode 9当前处于swift3.2和swift4交替的时期,各种pods的版本不尽相同,手动修改又太麻烦。因此直接修改podfile就好了。之后就可以一点点把swift3.2的库转移成swift4的库了。

非原创,主要来源于 https://github.com/CocoaPods/CocoaPods/issues/6791 下面 @kylef 的回复,不过他少了个end...

这里增加了print来辅助确认是否修改成功了,下面的代码放在podfile最后即可。

swift_32 = ['FontAwesome.swift','FontAwesome.swift-FontAwesome.swift']
swift4 = ['R.swift.Library','SnapKit','SwiftDate']

post_install do |installer|
    installer.pods_project.targets.each do |target|
        swift_version = nil
        
        if swift_32.include?(target.name)
            print "set pod #{target.name} swift version to 3.2\n"
            swift_version = '3.2'
        end
        
        if swift4.include?(target.name)
            print "set pod #{target.name} swift version to 4.0\n"
            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

你可能感兴趣的:(Cocoapods 指定三方库的swift版本)