Has anyone successfully defined and used a property wrapper in Xcode 11?
I have tried, using the Clamping example in the proposal. If I don't use the property, it builds fine. However, if I try to define a property using the Clamping, then Xcode cannot compile the project, rather it seems to become stuck indexing files.
Yes, it works for me. The only issue I ran into was when I was using a protocol, like @ObjectBinding var foo: FooProtocol instead of @ObjectBinding var foo: ConformsToFooProtocol.
import Foundation
@propertyWrapper
struct Clamping<V: Comparable> {
var value: V
let min: V
let max: V
init(initialValue: V, min: V, max: V) {
self.value = initialValue
self.min = min
self.max = max
assert(self.value >= self.min && self.value <= max)
}
var wrappedValue: V {
get { return value }
set {
if newValue < min {
value = min
} else if newValue > max {
value = max
} else {
value = newValue
}
}
}
}
struct Color {
@Clamping(min: 0, max: 255) var red: Int = 127
@Clamping(min: 0, max: 255) var green: Int = 127
@Clamping(min: 0, max: 255) var blue: Int = 127
@Clamping(min: 0, max: 255) var alpha: Int = 255
}
If I comment out the definition of Color, it builds fine. As soon as I put it back in, I have problems.
Yes, I will file a bug. However, I'm curious what code propertyWrapper you wrote that didn't cause the compiler to freak out. I'm simply trying to play with property wrappers and some working code would be a good starting point since the compiler doesn't love me today.
I've just released a new Kit named ValidatedPropertyKit which shows a different more advanced example of how to use and implement a Property Wrapper. Hope this helps
Not sure if you intended to ping me or the author of this thread. I can clearly say that I know property wrappers in out as I'm like the loudest person in the related threads. ;)