gpt4 book ai didi

ios - #if 和 #ifdef Objective-C 预处理器宏有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 11:48:06 28 4
gpt4 key购买 nike

如何在build设置中定义预处理器宏,例如 IPAD_BUILD 和 IPHONE_BUILD(以及如何在我的工厂方法中使用它们)?

我现在正在使用这些,如果知道后面发生了什么会很酷。

最佳答案

/#if 照常工作,如果:

#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

关于ios - #if 和 #ifdef Objective-C 预处理器宏有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12782289/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com