April 2026
Intermediate
683 pages
25h 29m
English
Before you move on to the next chapter, let’s address a useful concept: type aliases. A type alias allows you to provide a new (and hopefully more meaningful) name for an existing data type. Once a type alias is declared, it can be used instead of the original type name throughout the program. That approach improves the readability of the codebase. In this section, we’ll discuss both basic and complex type aliases.
In its basic usage, type aliases can be used as alternative names for basic Swift types. Listing 2.99 demonstrates an example of that approach, in which MoneyAmount has been declared as an alternative name for Float.
typealias MoneyAmount = Floatlet budget: MoneyAmount = 100let price: MoneyAmount ...
Read now
Unlock full access