Has anybody tried to use build configuration flags in a Swift based Pod? I am trying to use a post_install hook to add "OTHER_SWIFT_FLAGS" to a private Swift pod that I'm working on. Basically, I want to be able to do something like #if DEV #elseif QA #else #endif
to change endpoints based on the target that I'm using. The project I'm integrating the pod with also uses DEV & QA flags which work fine with corresponding DEV & QA targets.
Here is a post_install hook that I came up using help from other similar posts:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'Pods-Test-QA'
puts "Found #{target.name}. Adding Swift Flag..."
target.build_configurations.each do |config|
puts "Configuration: #{config}"
config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DQA'
puts "#{config.build_settings['OTHER_SWIFT_FLAGS'].inspect}"
end
end
if target.name == 'Pods-Test-DEV'
puts "Found #{target.name}. Adding Swift Flag..."
target.build_configurations.each do |config|
puts "Configuration: #{config}"
config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_SWIFT_FLAGS'] << '-DDEV'
puts "#{config.build_settings['OTHER_SWIFT_FLAGS'].inspect}"
end
end
end
end
After running pod install
the post_install successfully adds the flags as shown in the image below for Pods-Test-QA & Pods-Test-DEV.
However, when I run the project using QA or DEV targets and use the following flags it always hits PROD:
#if DEV
print("DEV ENVIRONMENT")
#elseif QA
print("QA ENVIRONMENT")
#else
print("PROD ENVIRONMENT")
#endif
Is there something I'm missing?
Also, for some reason Pods-Test-QA.debug.xcconfig
& DEV
don't seem to be updated with the flags I've added. Does anyone have any idea why it's not updating in the .xcconfig files?
OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS"
Any help would be appreciated. Thanks in advance.
Using:
- cocoapods (1.0.1)
- Xcode 7.3.1