我可以#ifdef #imports 吗?
我可以在 Objective-C 中 #ifdef #imports 吗?
例如:
#ifdef USE_A
#import "ClassA.h"
#endif
#ifdef USE_B
#import "ClassB.h"
#endif
Can I #ifdef #imports in objective-c?
For example:
#ifdef USE_A
#import "ClassA.h"
#endif
#ifdef USE_B
#import "ClassB.h"
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这个:
有效。
Yes, this:
is valid.
我相信它的
#ifdef __OBJC__
指令可以确保导入以下 Objective-C 库。该if
的目的是除非有必要,否则不导入它们。此外,通过这种方式,代码仍然可以与可能想要使用该 C 文件中的功能的常规 C 代码兼容(至少在我看来是这样)。通过仅在定义 OBJC 时包含这些库,可以确保仅在为目标 c 而不是标准 C 进行编译时导入这些库。I believe its
#ifdef __OBJC__
directive to ensure that following libraries for Objective-C are imported. The purpose of thatif
, is to not import them unless it is necessary. Also, this way the code can still be compatible with regular C code that may want to use the functionality in that C file (at least that's what it looks like to me). By including those libraries only when OBJC is defined it ensures that the libraries are ONLY imported when you are compiling for objective c and not for standard C.是的,您可以在 Objective-C 中使用
#ifdef
#imports
。该块称为条件组。当且仅当定义了 MACRO 时,受控文本才会包含在预处理器的输出中。我们说,如果定义了 MACRO,则条件成功;如果未定义,则条件失败。有关更多信息,请参阅 GCC 在线文档。
Yes, you can use
#ifdef
#imports
in objective-c.This block is called a conditional group. controlled text will be included in the output of the preprocessor if and only if MACRO is defined. We say that the conditional succeeds if MACRO is defined, fails if it is not. For more information take a look at GCC online docs.