![](/img/trans.png)
[英]What's the difference between synchronous and asynchronous calls in Objective-C, versus multi-threading?
[英]What's the difference between #if and #ifdef Objective-C preprocessor macro?
如何在构建设置中定义预处理器宏,如IPAD_BUILD和IPHONE_BUILD(以及如何在我的工厂方法中使用它们)?
我现在正在用这些,想知道背后会发生什么事情会很酷。
/#如果正常工作,如果:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
/ #ifdef表示“如果已定义 - 某些值或宏”:
#ifdef RKL_APPEND_TO_ICU_FUNCTIONS
#define RKL_ICU_FUNCTION_APPEND(x) _RKL_CONCAT(x, RKL_APPEND_TO_ICU_FUNCTIONS)
#else // RKL_APPEND_TO_ICU_FUNCTIONS
#define RKL_ICU_FUNCTION_APPEND(x) x
#endif // RKL_APPEND_TO_ICU_FUNCTIONS
要么:
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif
使用此链接获取更多信息http://www.techotopia.com/index.php/Using_Objective-C_Preprocessor_Directives
要测试你是否运行iPad,你应该像这样:
#define USING_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
if (USING_IPAD) {
NSLog(@"running iPad");
}
这是另一个有用的预处理器函数:
#ifdef DEBUG
//here we run application through xcode (either simulator or device). You usually place some test code here (e.g. hardcoded login-passwords)
#else
//this is a real application downloaded from appStore
#endif
宏可以是未定义的,可以没有值定义,也可以用某个值定义,可能是数字。 例子:
#undef MACRO
#define MACRO
#define MACRO ??????
#define MACRO 0
#define MACRO 1
#ifdef MACRO或#if defined(MACRO)检查是否定义了宏,有无值。
#if MACRO替代宏定义; 如果没有定义宏,那么它将替换0.然后它会计算它找到的表达式。 如果我们采用上面的五个例子,#if MACRO将变成
#if 0
#if
#if ??????
#if 0
#if 1
编号2和3给出编译时错误。 数字1和4的计算结果为false,因此将跳过以下代码。 数字5的评估结果为true。
#if更灵活:你可以写
#if MACRO == 2
如果宏被定义为例如,它将只编译以下代码
#define MACRO 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.