April 2026
Intermediate
683 pages
25h 29m
English
You learned about Swift functions in Chapter 5. Then, in Chapter 7, you also learned that enumerations can contain functions. Likewise, structs can contain functions as well. In this section, we will walk you through different types of struct functions.
Let’s go in logical order. First and foremost, structs feature a special function called init. As its name implies, init ought to be used to initialize properties. Each struct may contain only one init function (and overloads it if necessary). This function is automatically called only once when the struct is instantiated for the first time.
Let’s see init in action for a better understanding. Listing 8.18 contains a simple structure, which is a customer ...
Read now
Unlock full access