articles
articles copied to clipboard
Cannot compile property wrapper
Thx for you article https://nshipster.com/propertywrapper/.
With Xcode 11 beta 6 , there are some compile errors:
First this piece of code cannot be compiled:
`import Foundation
@propertyWrapper struct Versioned<Value> { private var value: Value private(set) var timestampedValues: [(Date, Value)] = []
var wrappedValue: Value {
get { value }
set {
defer { timestampedValues.append((Date(), value)) }
value = newValue
}
}
init(initialValue value: Value) {
self.wrappedValue = value
}
}`
Second, it seems that we can't get the property wrapper object with $ operator any more. Xcode can't figure it out. (Seems ok with Xcode 11 beta 2)
Indeed, property wrappers have gone through a few rounds of revision since the article was originally published. I'll revisit and update it for Xcode 11 once the final GM is made available.
After a an hour of struggling, Xcode told me that the parameter name initialValue
is deprecated in favour of wrappedValue
.
So the following should work
init(wrappedValue value: Value) {
self.wrappedValue = value
}
@mattt can you confirm this + update the page? :)