I need to make a define but if I use iPad or iPhone I need different values in this case.
So, as I think it should looks like this:
#ifdef UI_USER_INTERFACE_IDIOM == iPAD
#define ROWCOUNT 12
#else
#define ROWCOUNT 5
#endif
Is there some solution to get it?
Where you typically used the #define directive to define a primitive constant in C and Objective-C, in Swift you use a global constant instead. For example, the constant definition #define FADE_ANIMATION_DURATION 0.35 can be better expressed in Swift with let FADE_ANIMATION_DURATION = 0.35 .
What Are Macros? In the context of iOS, a macro is a phrase or text string that can be inserted by the system keyboard automatically when triggered by a user pressing a short, specific sequence of keys.
A macro is a fragment of code that is given a name. You can define a macro in C using the #define preprocessor directive. Here's an example. Here, when we use c in our program, it is replaced with 299792458 .
UI_USER_INTERFACE_IDIOM
is a macro that expands to some expression that checks the type of hardware at runtime, not at compile time. Thus you would want to change your definition of ROWCOUNT
to be a variable rather than a const or macro.
NSUInteger rowCount;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
rowCount = 12;
else
rowCount = 5;
or more concisely:
NSUInteger rowCount = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 12 : 5;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With