如何在 Podfile 中为特定 pods 设置版本?

How to set up versions for specific pods in Podfile?

这就是我在 Podfile 中所做的:

post_install do |installer|
    installer.pods_project.targets.each do |pod|
        pods = { 'CDMarkdownKit': '4.0', 'MessageKit': '4.0', 'LocalizationKit': '4.0', 'RxKeyboard': '4.0', 'JWTDecode': '3.1'}
            if pods.keys.include?(pod.name)
                pod.build_configurations.each do |config|
                    config.build_settings['SWIFT_VERSION'] = pods[pod.name]
                end
            end
        end
    end
end

但这行不通。我不知道为什么。这里有什么问题?

您应该对值使用符号。更新后的代码如下:

post_install do |installer|
    installer.pods_project.targets.each do |pod|
        pods = {'CDMarkdownKit': '4.0', 'MessageKit': '4.0', 'LocalizationKit': '4.0', 'RxKeyboard': '4.0', 'JWTDecode': '3.1'}
        if pods.has_key?(pod.name.to_sym)
            pod.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = pods.values_at(pod.name.to_sym)
            end
        end
    end
end