为cocoapod依赖关系指定预处理器宏,而不分叉它 [英] Specifying preprocessor macros for a cocoapod dependency, without forking it

查看:179
本文介绍了为cocoapod依赖关系指定预处理器宏,而不分叉它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 Cocoapod 管理的XCode工作区,对外部库有一些依赖性。其中之一 MTDates 扩展了 NSDate NSDateComponents 使用带前缀的方法,或者如果定义了某个预处理器宏则不带前缀(这就是我想要的)。

I have an XCode workspace managed by Cocoapod with a few dependencies to external libraries. One of them, MTDates, extends NSDate and NSDateComponents with either prefixed methods, or non-prefixed if a certain preprocessor macro is defined (which is what I want).

我可以在一些地方放置预处理器宏定义,以使编译的库提供非前缀的方法,但是似乎所有这些都将尽快重置。当我要求 Cocoapod 更新项目时,这使我认为这些配置是由pod规范驱动的。其中包括:

There are a few places where I can put the preprocessor macro definition in order to have the compiled library provide the non-prefixed methods, but all seem to be reset as soon as I ask Cocoapod to update the project, which leads me to think that these configs are driven by the pod spec. These include :


  • 吊舱的目标构建设置

  • 吊舱的私人 Cocoapod的 Targets Support Files
  • 中的.xcconfig 文件
  • The pod's target build settings
  • The pod's private .xcconfig file in Cocoapod's Targets Support Files

更改豆荚的规格会需要管理我自己的库版本,从而导致 cocoapods 失去更新新版本时的功能。所以我的问题是:有没有一种方法可以为 cocoapod 依赖关系指定预处理器宏,而无需分叉pod并更改pod的spec本身?

Changing the pod's spec would require to manage my own version of the library, whereby losing the ability for cocoapods to update it when a new version comes around. So my question is: is there a way to specify a preprocessor macro for a cocoapod dependency, without forking the pod and changing the pod's spec itself?

编辑

有一个与此有关的公开问题,似乎迫在眉睫。

There is an open issue about this, that seem to be just around the corner.

推荐答案

此功能现已可用。这是您可以放在Podfile底部以根据特定配置添加宏的示例。

This functionality is now available. Here is an example of what you could put at the bottom of your Podfile to add a macro based on a specific configuration.

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == "Pods-TweaksBuildConfigurationsDemo-Tweaks"
      target.build_configurations.each do |config|
        if config.name == 'QA'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FB_TWEAK_ENABLED=1']
        end
      end
    end
  end
end

这篇关于为cocoapod依赖关系指定预处理器宏,而不分叉它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆