I have a ObservableObject
class called MyObjectModel
that is passed to a struct like this:
var body: some View {
MyView(myObjectModel)
But on another context I do not have a model to pass, so I want to call MyView
simply as
var body: some View {
MyView()
So I thought I could initialize MyView
like
struct MyView: View {
@ObservedObject private var model: MyObjectModel?
init(model: MyObjectModel? = nil) {
self.model = model
}
But Xcode will not let me use @ObservedObject
on an optional.
How do I do that?