get
and set
didSet
and willSet
The docs call these property observers.
_read
and _modify
- Yielding accessors in Swift
- See Ownership in Swift
- Modify Accessors - Evolution / Pitches - Swift Forums
init accessor
struct Angle {
var degrees: Double
var radians: Double {
@storageRestrictions(initializes: degrees) // 👈🏼
init(initialValue) {
degrees = initialValue * 180 / .pi
}
get { degrees * .pi / 180 }
set { degrees = newValue * 180 / .pi }
}
init(degrees: Double) {
self.degrees = degrees // initializes 'self.degrees' directly
}
init(radiansParam: Double) {
self.radians = radiansParam // calls init accessor for 'self.radians', passing 'radiansParam' as the argument
}
}