Skip to content

Instantly share code, notes, and snippets.

@haifengkao
Created September 5, 2022 08:23
Show Gist options
  • Save haifengkao/10692fac1f5f642b89bb57f1e6bdc9d6 to your computer and use it in GitHub Desktop.
Save haifengkao/10692fac1f5f642b89bb57f1e6bdc9d6 to your computer and use it in GitHub Desktop.
broken property wrapper syntax in Xcode 14 beta 5
@propertyWrapper
struct SmallNumber {
private var maximum: Int
private var number: Int
var wrappedValue: Int {
get { return number }
set { number = min(newValue, maximum) }
}
init() {
maximum = 12
number = 0
}
init(wrappedValue: Int) {
maximum = 12
number = min(wrappedValue, maximum)
}
init(wrappedValue: Int, maximum: Int) {
self.maximum = maximum
number = min(wrappedValue, maximum)
}
}
struct SomeStructure {
@SmallNumber var someNumber: Int
}
func someFunction() {
@SmallNumber var myNumber: Int = 0
var someStructure = SomeStructure()
someStructure.someNumber = 4
print(someStructure.$someNumber) // Error: Value of type 'SomeStructure' has no member '$someNumber'
myNumber = 10
// now myNumber is 10
myNumber = 24
// now myNumber is 12
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment