Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27191

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

Upvotes: 2

Views: 446

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409472

If UIUserInterfaceIdiomPad is not a preprocessor symbol, then it can't be used in preprocessor conditionals.

Upvotes: 2

Paul R
Paul R

Reputation: 213190

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

Upvotes: 3

Related Questions