April 2026
Intermediate
683 pages
25h 29m
English
Struct is another data type open to extensions. For a struct example, let’s apply a subscript and function extension to an RGBColor struct, as shown in Listing 11.4.
struct RGBColor { let red: Int let green: Int let blue: Int}
Listing 11.4 Basic Form of RGBColor
RGB stands for red, green, and blue and is the standard model used to express colors in user interfaces such as web pages. Red, green, and blue are three primary colors of light. By mixing different intensities of those colors, you can produce any other color.
For example, pure red is (255, 0, 0); that is, it has the maximum value for red and the minimum value for other colors. Black is (0, 0, 0), meaning that it has the minimum value ...
Read now
Unlock full access