import SwiftUI import Observation struct ContentView: View { @State var count = 0 var body: some View { VStack { Text(count.description) Button { count += 1 print("count: \(count)") } label: { Text("count") } ChildView() } } } struct ChildView: View { @StateObject var viewModel: ChildViewModel init() { _viewModel = .init(wrappedValue: { print("called") return ChildViewModel() }()) } var body: some View { Text("child") } } @MainActor @Observable final class ChildViewModel: ObservableObject { init() { print("init") } deinit { print("deinit") } }