class implementing View and bindings

Easiest solution for several things I'm doing to to implement Views as classes rather than structs. Don't see anything that prevents it and it mostly works, except for bindings. Example:


final class ContentView : View {
   
    @State var test = false
   
    var body: some View {
        let a=test
        return Text("Hello World")
    }
}


Which yields:


Thread 1: Fatal error: Accessing State<Bool> outside View.body


..on line 6.


Any thoughts?

I don't think you'll be able to access State variables as members of a class (even though I think internally there's 'no difference'). Maybe file a bug since you're technically accessing the variable inside the body and getting a thrown error. Out of curiosity, what activity makes a class easier than a struct for describing a SwiftUI view?


I've ran into more than a few things where I've fallen back on appkit or uikit and wrapped classes in a representable view, but haven't ran into any task yet outside of incorporating other kit code that requires a class. I only ask because I'm pretty new to Swift in general, so I'm learning how much I don't know yet, and i'm curious. I've 20 years of coding in c++ and java (work related), but I'm curious what I don't know here lol.

class implementing View and bindings
 
 
Q