swift - Cocoapod podspec 上的预处理器标志

标签 swift frameworks cocoapods preprocessor

我正在构建一个在其中一种方法中使用预处理器标志的框架。类似于下面的代码:

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 中定义这个东西?

最佳答案

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

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

关于swift - Cocoapod podspec 上的预处理器标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38784082/

相关文章:

ios - 优化代码物理

swift - 使用 RxSwift 更改序列 Observable 内对象的值

php - 构建轻量级且高度数据库驱动的网站的解决方案?

ios - 无效的 Swift 支持

ios - 在私有(private) pod 的情况下无法访问主页?

ios - 集中放置 Collection View 单元格

ios - 使用 Swinject 将 ViewModel 有条件注入(inject)到 ViewController 中

java - 我正在 selenium 自动化中创建页面对象模型框架,并且面临 java 空指针异常

ios - 如何在 xcode 中添加 QuartzCore.framework

swift - 框架中的 pod,在 swift 中为主项目导入该框架