access parent project OTHER_SWIFT_FLAGS from pod

眉间皱痕 提交于 2019-12-11 02:31:33

问题


Building a custom pod for a private framework, in my main project i use custom OTHER_SWIFT_FLAGS.

In theory it should be possible to override the settings of the pod during the install based on the main project but there is no documentation on how to do so.

So far my attempts failed, any hint? Looks like project(https://guides.cocoapods.org/syntax/podfile.html#project) should be the way to go but again, no documentation.


回答1:


So basically it looks like this. Accessing the xcode project, then accessing the pod and looping through each config to set the proper value.

post_install do |installer|
require 'xcodeproj'
project_path = 'pathTo/myProj.xcodeproj' # path to your xcode project
project = Xcodeproj::Project.open(project_path)
project.targets.each do |target|
    if target.name == 'myTarget' # name of the target in your main project containing the custom flag
        installer.pods_project.targets.each do |podTarget|
            if podTarget.name == 'myPod' #name of your pod
                target.build_configurations.each do |targetConfig|
                    podTarget.build_configurations.each do |podConfig|
                        podConfig.build_settings["OTHER_SWIFT_FLAGS"] = targetConfig.build_settings["OTHER_SWIFT_FLAGS"]
                    end
                end

            end
        end
    end
end


来源:https://stackoverflow.com/questions/44949852/access-parent-project-other-swift-flags-from-pod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!