How do I support multi-window scenes in SwiftUI with Swift?

Supporting multi-window scenes in SwiftUI allows your application to provide optimized experiences across multiple displays, enhancing user productivity and interaction. This feature is especially beneficial for apps that require simultaneous tasks or focus on different aspects of the same task.

To implement multi-window support in your SwiftUI application, you utilize the `WindowGroup` and the scene's `commands` to handle multiple scenes. Here's a basic example demonstrating how to achieve this:

import SwiftUI @main struct MultiWindowApp: App { var body: some Scene { WindowGroup { ContentView() } .commands { CommandGroup(replacing: .appSettings) { Button(action: { // Action to open a new window NSApplication.shared.sendAction(#selector(NSWindow.newWindow(_:)), to: nil, from: nil) }) { Text("New Window") } } } } } struct ContentView: View { var body: some View { Text("Welcome to Multi-Window Support!") .padding() } }

SwiftUI multi-window support Swift macOS application development UI design