13.2 A Simple Property Wrapper Example
Perhaps the best way to understand property wrappers is to study a very simple example. Imagine a structure with a String property intended to contain a city name. Such a structure might read as follows:
struct Address {
var city: String
}
If the class was required to store the city name in uppercase, regardless of how it was entered by the user, a computed property such as the following might be added to the structure:
struct Address {
private var cityname: String = ""
var city: String {
get { cityname }
set { cityname = newValue.uppercased() }
}
}
When a city name is assigned to the property, the setter within the computed property converts it to uppercase...