I have a macOS app which I'd like to open several instances of in separate windows. For demonstration purposes, I have this tiny example project here:
import SwiftUI @main struct MultipleWindowsApp: App { var body: some Scene { WindowGroup { MyView() .environmentObject(ViewModel()) .frame(minWidth: 200, minHeight: 200) } } } struct MyView: View { @EnvironmentObject var vm: ViewModel var body: some View { Toggle(isOn: $vm.toggleState, label: { Text("Some Toggle") }) } } class ViewModel: ObservableObject { @Published var toggleState = false } As it is, a new window created from the menu bar will have a reference to the same ViewModel instance (toggling in one window toggles the other and vice versa). I failed to find a simple answer on how I can have different windows with their own respective viewmodels (please note: I am not handling documents here that need to get saved etc., I am just consuming and visualising an api in my app).