I have defined an enum, with a static property which loads a unit from user defaults. My question is how is this static property initialized? When a user changes defaults within my app, this property is not updated until restart.
enum Length: String, Some Protocols {
//...some stuff
static let preferredUnit: UnitLength = UserDefaults.standard.getUnit(forKey: .preferredUnitLength)
}
When I make this static constant a computed property, it’s still not updated when a user changes their preferred unit despite updating defaults on unit change.
enum Length: String, Some Protocols {
//...some stuff
var preferredUnit: UnitLength { UserDefaults.standard.getUnit(forKey: .preferredUnitLength) }
}
I leverage this static constant like so:
var someProperty: Measurement<UnitVolume> {
return value.converted(to: Volume.preferredUnit)
}
The new unit is only loaded on app restart. I am okay with this, but would like to understand why.