How do I access a Macro defined in my pch from a cocoapods lib?

南笙酒味 提交于 2019-12-11 03:33:35

问题


Context

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.

Situation

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).

Problem

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.

Sum-Up

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!


回答1:


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.

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.



来源:https://stackoverflow.com/questions/30872130/how-do-i-access-a-macro-defined-in-my-pch-from-a-cocoapods-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!