Question

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?

Was it helpful?

Solution

#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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top