This led me to think that Property Wrappers are not included in the struct's initializer, and that's why they do not cause that error since they don't affect the initializer protection level.
I'm curious, why are Property Wrappers not included in the View initializer?
Both x and y are not included in the automatically synthesized initializer, because the variables are declared private. But you can define a custom one.
struct MyView: View {
private var x: Int = 0
@State private var y = 0
init(x: Int, y: Int) {
self.x = x
self.y = y
}
. . .
}
FYI that I find a way to verify the signature of the private synthesized init() by using static variable and Xcode autocomplete feature.
For the issue in the bug report, the synthesized init() includes y. It doesn't compile because the init() is private:
struct Struct {
// this works
static var shared = Struct(x: 1, y: 1)
var x: Int
private var y: Int = 0
}
When y is wrapped in a property wrapper, a similar experiment shows that synthesized init() includes y only if it doesn't have default value. Otherwise it doesn't (I'm also curious why).