是否可以将xcconfig包含在由CocoaPods

时间:2016-09-01 21:27:27

标签: cocoapods cocoapods-1.0.1

问题是:CocoaPods为我的项目生成xcconfig文件,我希望将xcconfig文件作为依赖项包含在其中。我可以在post_install钩子中做到吗? 我只发现XCBuildConfiguration有build_settings哈希,但据我所知,我只能添加或更改密钥,而不包含带有该哈希的语句。

1 个答案:

答案 0 :(得分:0)

按照this answer的说明,我可以更新xcconfig,并使用此代码将我的xcconfig文件包含在已生成的广告单元中:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        next unless target.name.include?("Pods-CNISDK")
        puts "Updating #{target.name}"
        target.build_configurations.each do |config|
          xcconfig_path = config.base_configuration_reference.real_path
          # read from xcconfig to build_settings dictionary
          build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]
          # write build_settings dictionary to xcconfig
          File.open(xcconfig_path, "w") do |file|
            file.puts "#include \"../configurations/Warnings.xcconfig\"\n"
            build_settings.each do |key,value|
              file.puts "#{key} = #{value}"
            end
          end
        end
      end
    end