#define 与 const 以及针对框架的链接
我有一个非常小的轻量级应用程序,它需要使用一些存储在更大框架中的常量。我不想复制这些常量并将它们硬编码到轻量级应用程序中,但我也不想必须链接到大型框架才能获取常量。
这些常量是使用头文件中的static NSString *const
定义的。将 static NSString *const
替换为 #define
是否可以防止我必须链接到整个框架?
老实说,我不完全确定链接是如何工作的,所以我可能错误地思考了这个问题
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果您 #define 常量,则只需 #import 包含它们的 .h 文件。
您确实需要注意 #define 常量是文字文本替换 - 它们没有“类型”等,就像静态常量值一样。
但另一种选择(仅适用于整数常量)是定义 C 风格枚举 在 .h 文件中。
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.