GoldenJoe GoldenJoe - 16 days ago 5
Objective-C Question

How to define a preprocessor macro that uses another as a conditional?

I have a game that uses some common macros to figure out what device the user is on:

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_4 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 480.0f)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0f)
#define IS_IPHONE_6P (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0f)


It's an older game, and I just want to use a multiplier adjust some positioning. A macro would be ideal:

#ifdef IS_IPHONE_6
#define SIZEMOD 1.172f
#elif IS_IPHONE_6P
#define SIZEMOD 1.6875f
#else
#define SIZEMOD 1.0f
#endif


Unfortunately, this checks to see if the macro
IS_IPHONE_6
is defined, which will always be true and therefore the wrong multiplier is used on other devices. How can I properly define
SIZEMOD
using a macro?

Answer

I hope I don't get downvoted to hell for this

Comments