articles icon indicating copy to clipboard operation
articles copied to clipboard

Cannot compile property wrapper

Open CharlieSuP1 opened this issue 4 years ago • 2 comments

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)

CharlieSuP1 avatar Aug 22 '19 10:08 CharlieSuP1

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.

mattt avatar Aug 27 '19 20:08 mattt

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? :)

fl034 avatar Jul 13 '20 14:07 fl034