Matrosov Alexander Matrosov Alexander - 4 months ago 24
iOS Question

Objective-C preprocessor directive issues

I have implemented this code for defining my constants:

#ifdef UI_USER_INTERFACE_IDIOM
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM == UIUserInterfaceIdiomPad)
#else
#define IS_IPAD() (false)
#endif

#if (IS_IPAD)
CGFloat const scrollSizeWidth = 768.0f;
CGFloat const scrollSizeHeight = 1004.0f;
#else
CGFloat const scrollSizeWidth = 320.0f;
CGFloat const scrollSizeHeight = 460.0f;
#endif


But it always display 320.0f and 460.0f for my variables.

UPDATE:
As k3a user found UI_USER_INTERFACE_IDIOM does not work for iOS 8.3, because it's not longer a define it's a static inline.

Check this answer as well:
link

Answer

Change:

#ifdef UI_USER_INTERFACE_IDIOM
#define IS_IPAD() (UI_USER_INTERFACE_IDIOM == UIUserInterfaceIdiomPad)
#else
#define IS_IPAD() (false)
#endif

to

#ifdef UI_USER_INTERFACE_IDIOM
#define IS_IPAD (UI_USER_INTERFACE_IDIOM == UIUserInterfaceIdiomPad)
#else
#define IS_IPAD (false)
#endif