Before iOS17 injecting viewModels with @StateObject was done this way as per SwiftUI team at WWDC23
@StateObject private var viewModel: FooVM
init(viewModel: @autoclosure @escaping () > FooVM) {
self-_viewModel = StateObject(wrappedValue: viewModel())
}
What is the appropriate way to do it with the new @Observable macro and @State?