Cocoapod的podspec中的预处理器标志

7
我正在构建一个框架,其中一个方法使用了预处理器标记。代码如下所示:
public func heyStuck(overflow: String) {
    #if DEBUG
        print(overflow)
    #else
        print("¯\\_(ツ)_//¯")
    #endif
}

关键是我正在使用Cocoapods导入我的框架,所以为了为框架定义DEBUG标志,在我的App Podfile中必须像这样做:

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            if config.name != 'Release'
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'DEBUG=1']
        end
        end
    end
end

有没有办法将此信息添加到podspec文件中,以便避免应用程序在其Podfile中定义此内容?

2个回答

11

我终于搞定了,在我的podspec文件中使用以下魔法:

s.pod_target_xcconfig = {
  'OTHER_SWIFT_FLAGS[config=Debug]' => '-DDEBUG',
}

0

谢谢@Adam,但在Swift中不起作用,因为没有#ifdef。最终我通过添加一个仅针对Debug的条件编译标志来解决了这个问题。我已将答案作为答案添加。再次感谢。 - user6219996

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接