如何从cocoapods库访问在我的pch中定义的宏? [英] How do I access a Macro defined in my pch from a cocoapods lib?

查看:380
本文介绍了如何从cocoapods库访问在我的pch中定义的宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个大项目,因此应用程序与某些通用代码分开。每个人都在自己的存储库中,应用程序通过cocoapods将通用代码用作lib。

We have a big project, so the application is separated from some common code. Each one goes in its own repo, and the app uses the common code as a lib via cocoapods.

现在,我们需要切换lib中包含的一些非常特定的功能。但是启用/禁用它的条件是在application-prefix.pch文件中定义的宏(我知道,不是很酷)。

Now, we need to toggle some very specific functionality, contained in the lib. But the condition to enable/disable it is a MACRO defined in the application-prefix.pch file (I know, not cool).

库中的代码(包含在Pod中)不会看到 pch文件中定义的MACRO。因此,我们实际上无法切换此行为。

The code in the lib (included as a Pod) doesn't "see" the MACRO defined in the pch file. So, we can't actually toggle this behaviour.

我见过的唯一选择是添加后安装挂钩到我们的Podfile中,但是它似乎可以与构建设置中定义的MACROS一起使用;而在这种情况下,MACRO在pch文件中定义。而且我真的真的不想在lib或podfile中添加值。

The only alternative I've seen is to add a post-install hook in our Podfile, but it seems to mostly work with MACROS defined in the Build Settings; while in this case the MACRO is defined in the pch file. And I really really really don't want to add the values in the lib or in the podfile.

任何向我指出正确方向的建议或想法都将不胜感激!

Any advice or idea to point me in the right direction will be greatly appreciated!

推荐答案

在Cocoapod的源代码中无法使用应用程序项目的宏-这是因为整个pod目标将在应用程序目标甚至尚未开始构建之前就已构建,因此pod无法了解宏。

There's no way to use a macro of an application project in a the source code of a Cocoapod - this is because the entire pod target will be build before the application target even starts building, so there's no way for the pod to know about the macro.

我的第一个直觉是使用后安装像你提到的那样钩。但是,您也可以在另一个窗格中添加所需的宏,并使每个目标(包括窗格和主应用程序)都依赖于该新窗格。

My first instinct would be to use a post-install hook like you mentioned. However, you could also add the macro you need in another pod, and have every target, including pods and the main application, depend on that new pod.

另一种更简洁的方法:设计pod代码,使其能够在有或没有的特定功能下进行操作(例如,通过布尔标志)。然后,根据应用程序中宏的值,选择将该标志作为true或false传递给pod代码。

Another, cleaner way: design the pod code to be able to operate with or without the specific functionality that you want to gate on (via, say, a boolean flag). Then, depending on the value of the macro in the application, choose to pass that flag to the pod code as true or false.

这篇关于如何从cocoapods库访问在我的pch中定义的宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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