swiftxcodecocoapodsxcodeproj

access parent project OTHER_SWIFT_FLAGS from pod


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.


Solution

  • 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