April 2026
Intermediate
683 pages
25h 29m
English
In this final section, you will learn about some advanced features of structs, which go beyond their daily use cases and are typically used when a special need arises.
In Swift structs, lazy properties are used to defer the initialization of a property until it is first accessed. Once the lazy property is calculated, it is cached automatically; the calculated result then is returned on later calls. This is useful in terms of performance improvement, especially when the computation of the property is expensive and might not be needed in every instance of the struct.
Let’s go over the concrete example in Listing 8.36, where the averageScore lazy property is featured. This property is simply calculating ...
Read now
Unlock full access