![](/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.