13.3 Supporting Multiple Variables and Types
In the above example, the property wrapper accepted a single value in the form of the value to be assigned to the property being wrapped. More complex property wrappers may also be implemented that accept other values that can be used when performing the computation. These additional values are placed within parentheses after the property wrapper name. A property wrapper designed to restrict a value within a specified range might read as follows:
struct Demo {
@MinMaxVal(min: 10, max: 150) var value: Int = 100
}
The code to implement the above MinMaxVal property wrapper could be written as follows:
@propertyWrapper
struct MinMaxVal {
var value: Int
let max: Int
let min: Int
init(wrappedValue: Int, min: Int, max: Int) {
value = wrappedValue
self...