为Cocoapods依赖添加环境宏

为Cocoapods依赖添加环境宏

在Podfile里设置

# 要添加环境宏的依赖列表
add_test_pod = ['BBB', 'AAA']

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ENABLE_BITCODE'] = 'YES'
            if (config.name == 'Test') and add_test_pod.include?(target.name)
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= []
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] |= ['$(inherited)', 'TEST=1']
                config.build_settings['OTHER_SWIFT_FLAGS'] ||= []
                config.build_settings['OTHER_SWIFT_FLAGS'] |= ['$(inherited)', '-DTEST']
            end
        end
    end
end

||= []确保variables是一个有效的数组
|=则是A数组和B数组的并集(甚至还会去重)

Inject TEST macros into Pods | ckqing.home
ios - DEBUG preprocessor macro not defined for CocoaPods targets - Stack Overflow

你可能感兴趣的:(为Cocoapods依赖添加环境宏)