risposta

44

/# se funziona come al solito se:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    return YES; 
    } 
#endif 
    return NO; 
} 

/# ifdef significa "se definito - qualche valore o macro":

#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 

o:

#ifdef __OBJC__ 
    #import <Foundation/Foundation.h> 
#endif 

Usa questo link per maggiori informazioni http://www.techotopia.com/index.php/Using_Objective-C_Preprocessor_Directives

Per verificare se in esecuzione iPad o non si dovrebbe avere smth come questo:

#define USING_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad 

if (USING_IPAD) { 
    NSLog(@"running iPad"); 
} 

Ecco un altro utili funzioni del preprocessore:

#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 
+0

Grazie. Per sicurezza: #define IPAD_BUILD è sufficiente per essere definito (senza alcun valore?) In questo caso, #ifdef IPAD_BUILD restituisce true? – Geri

+0

Sembra sì ._____ – Geri

+0

effettivamente no =) Cambierò la risposta. – Stas

9

Una macro può essere indefinito, può essere definito senza valore , o può essere definito con un certo valore, possibilmente un numero. Esempi:

#undef MACRO 
#define MACRO 
#define MACRO ?????? 
#define MACRO 0 
#define MACRO 1 

#ifdef MACRO o #if definiti (MACRO) verifica se la macro viene definita, con o senza valore.

#if MACRO sostituisce la definizione della macro; se la macro non è definita, sostituisce 0. Quindi valuta l'espressione trovata. Se prendiamo i cinque esempi sopra riportati, #if MACRO sarà trasformato in

#if 0 
#if 
#if ?????? 
#if 0 
#if 1 

numero 2 e 3 dà un errore di tempo di compilazione. I numeri 1 e 4 sono valutati come falsi, quindi il codice seguente viene saltato. Il numero 5 è vero.

#if è più flessibile: Si potrebbe scrivere

#if MACRO == 2 

che solo compilare il seguente codice se la macro è stata definita per esempio come

#define MACRO 2