While we know that we can use colors with the hexadecimal notation, Sparrow provides some shorthand constants for the most commonly used colors. In the previous example, instead of using 0xffff00
for the color yellow, we used SP_YELLOW
.
To generalize, macros are handy little functions that allow us to simplify the workflow when working with repetitious tasks.
Macros in Objective-C are preprocessor directives and work the same way that macros work in C and C++. Before the code is compiled, the preprocessor goes through the entire code and replaces all occurrences of the macro with the result of the macro.
While we could write each color in the hexadecimal color value notation, sometimes it does make more sense to use an RGB value. The SP_COLOR
macro does exactly that, converting a RGB color into a hexadecimal color value.
In this section, we will look at what the different kinds of macros are and how to use them.