【问题标题】:Is it possible to include xcconfig into one that generated by CocoaPods是否可以将 xcconfig 包含在 CocoaPods 生成的文件中
【发布时间】:2016-09-01 21:27:26
【问题描述】:

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

【问题讨论】:

    标签: cocoapods cocoapods-1.0.1


    【解决方案1】:

    按照this answer 的说明,我能够更新xcconfig 并使用此代码将我的xcconfig 文件包含到生成的pod 中:

        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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 2010-12-06
      • 1970-01-01
      • 2012-08-11
      相关资源
      最近更新 更多