1

I'm figuring out how to determine iOS device types and came across this solution: https://stackoverflow.com/a/16319767/440646

The line of question:
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

I read that #define is a preprocessor that get evaluated before compilation, so is the UI_USER_INTERFACE_IDIOM() statement.

My question is how does the compiler knows which device to compile for, since we'll only get to know which device a user is using during runtime?

Community
  • 1
  • 1
resting
  • 16,287
  • 16
  • 59
  • 90
  • 1
    Understand that `#define` defines substitution text. Wherever you code `IS_IPAD`, the text `(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)` be substituted in it's place before compilation. You could accomplish the same test by coding `(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)` directly in an `if` statement. The "macro" defined in the `#define` is just a convenience. – Hot Licks Mar 24 '14 at 01:47

1 Answers1

0

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) does not check for a specific device (iPhone 4, iPhone 5, etc) but a device category (iPhone, iPad).

Here is another SO question that shows what the macro does. This will help you understand: Is it safe to check for UI_USER_INTERFACE_IDIOM() to determine if it's an iPhone or iPad?

Community
  • 1
  • 1
David Andreoletti
  • 4,485
  • 4
  • 29
  • 51