#define vs const and linking against frameworks

こ雲淡風輕ζ 提交于 2020-01-07 06:15:27

问题


I have a really small lightweight application which needs to use some constants that are stored in a larger framework. I don't want to duplicate these constants and hardcode them into the lightweight application but I also don't want to have to link against the large framework to just get the constants.

The constants are defined using static NSString *const in a header file. Does replacing the static NSString *const with #define prevent me from having to link against the whole framework ?

To be honest, I'm not entirely sure how linking works so I'm probably thinking about this incorrectly


回答1:


Yes, if you #define the constants you just need to #import the .h file that contains them.

You do need to be aware that the #defined constants are literal text substitutions -- they have no "type", etc, as static const values would.

But another option (for integer constants only) is to define C-style enums in a .h file.



来源:https://stackoverflow.com/questions/8017032/define-vs-const-and-linking-against-frameworks

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