Properties & Subscripts
Use lazy stored properties, get/set computed properties, property observers, and subscripts for custom indexing.
Intro
This lesson covers advanced properties: lazy, computed with get/set, observers, plus custom subscripts.
lazy property
lazy properties are created only on first access. Useful for expensive work.
struct DataLoader {
lazy var data: [Int] = {
print("Loading...")
return [1,2,3]
}()
}
var loader = DataLoader()
print("before access")
print(loader.data)All lessons in this course
- Properties & Subscripts
- lazy & property observers
- Computed properties with get/set
- Subscripts for custom indexing