Property wrappers
Property wrappers were introduced in Swift 5.1 with SE-0258 and they enable property values to be wrapped using a custom type. In order to perform this wrapping, we must create a custom attribute and a type that will handle the attribute. To see an example of this, let's say that we want to trim all of the whitespace characters from the beginning and the ending of our string values. We could do this by using the getter and setter methods of our properties to trim the whitespace characters; however, we would have to put this logic in for each property that we wanted to trim. With property wrappers, we would do this much more easily. We will start off by creating our custom type that will be used as a wrapper; we will name it Trimmed:
@propertyWrapper
struct Trimmed {
private var str: String = ""
var wrappedValue: String {
get { str }
set { str = newValue.trimmingCharacters(in: .whitespacesAndNewlines) }
}
init(wrappedValue...