April 2026
Intermediate
683 pages
25h 29m
English
In the previous chapter, you learned about computed properties for enumerations, remember? Structs feature computed properties in nearly the same way. Based on existing properties of a struct, you can compute new values when requested by the caller. Likewise, you can accept a computed value from the caller to interpret and break down into real properties. In this section, you will see examples of both.
This is going to be a familiar topic, similar to enumerations—so expect an easy ride! In a struct, a getter is a computed property that computes and returns a value based on existing properties. In Listing 8.12, isDead is a getter of the Monster struct.
struct Monster { @MainActor static var isPaused ...
Read now
Unlock full access