I have tried on Xcode 14 beta 5, beta 6 and recent RC1
All of them fail to compile. Xcode 13 works without any problems.
Is the property wrapper syntax changed on Swift 5.7?
struct SomeStructure {
@SmallNumber var someNumber: Int
}
func someFunction() {
@SmallNumber var myNumber: Int = 0
var someStructure = SomeStructure()
someStructure.someNumber = 4
// Error: Value of type 'SomeStructure' has no member '$someNumber'
print(someStructure.$someNumber)
}
The code you shared fails to compile in Xcode 13.4.1 as well as Xcode 14 for me, which is what I expected.
The $ prefixed property for your property wrapper returns the value that you have as your property wrapper's projectedValue property. If you don't define a projectedValue, no $ prefixed property is generated.
For example, redefining your property wrapper as shown below allows access with $
@propertyWrapper
struct SmallNumber {
private var maximum: Int
private var number: Int
var wrappedValue: Int {
get { return number }
set { number = min(newValue, maximum) }
}
var projectedValue: String {
return "the number is \(number)"
}
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)
}
}
The code you posted still doesn't compile with that change due to how things are set up in the function; looks like defining a property-wrapped property in a function isn't allowed.
I don't believe this was fixed in time for Xcode 14 RC. You can work around this by using a local function instead of a closure, pulling the local wrapped property outside of the closure, using a local struct that stores the property wrapper inside the closure, etc.
This doesn't follow. Property wrappers are for properties, but this does not mean they are exclusively for properties.
I just bought a bathmat recently, and it works perfectly for absorbing water after I take a shower, even though a shower is not a bath. Sometimes I put other electronics or even sheets of paper in my laptop bag, and it holds them just fine even though they are not laptops.