Assignment to @State var in init() doesn't do anything, but the compiler gen'ed one works

Oh and as a side note there is this artificial issue: [SR-12202] Property wrappers initialization is somehow artificially restricted for `State` · Issue #54627 · apple/swift · GitHub

Basically you cannot rely on the property = value syntax in the init if the PW has no mutable setter on its wrappedValue property. I understand why this is how it is right now, but theoretically the compiler should be able to diagnose this correctly and allow default initialization right through the wrapped property as a shorthand syntax (& kinda like late / out of line initialization) from within an init. That's why I consider this as a bug.

Related discussion: Why does this property wrapper code compile?

1 Like