Hello
Why does it give me an error when I pass 'name' at line 3?
Thank you
Why does it give me an error when I pass 'name' at line 3?
Code Block struct OtherView: View { @State private var name: String = "" @ObservedObject var use = Use(name: name) var body: some View{ VStack{ } } } class Use: ObservableObject { @Published var name: String init(name: String) { self.name = name } }
Thank you
In fact the message is pretty explicit.
You try to use self (by using its name property) before self is fully initialised (use is not yet defined).
That's a classical catch 22 situation in init.
Unfortunately, you cannot declare use as lazy because it is an observedValue.
But this should work
You try to use self (by using its name property) before self is fully initialised (use is not yet defined).
That's a classical catch 22 situation in init.
Unfortunately, you cannot declare use as lazy because it is an observedValue.
But this should work
Code Block struct OtherView: View { @State private var name: String = "" @ObservedObject var use : Use = Use(name: "") init() { use = Use(name: name) } var body: some View{ VStack{ } } }