SwiftUI on Mac: How to create App Scenes of different types?

I’ve got a Mac app with different kinds of windows. However, only Window1 is created on launch:

Code Block swift
import SwiftUI
@main struct MyApp: App {
  @SceneBuilder var body: some Scene {
    Window1()
    Window2()
  }
}
struct Window1: Scene {
  var body: some Scene {
    WindowGroup {
      Text("Window 1")
        .padding(100)
        .navigationTitle("Title 1")
    }
  }
}
struct Window2: Scene {
  var body: some Scene {
    WindowGroup {
      Text("Window 2")
        .padding(100)
        .navigationTitle("Title 2")
    }
  }
}


How do we create a Window2? Is this even possible? Documentation is not clear in this regard.

By the way, we have Settings window group on macOS. How does it work?

Replies

Hi, I have not found a way to create a second window, it may not have been added yet.

The Settings scene works only for macOS, so it needs to be wrapped with conditional compilation:
Code Block
#if os(macOS)
Settings()
#endif


If you add a settings scene, then the Preferences application menu is automatically added, and it is this that opens the second settings window. However, I have not yet found a programmatic way to call this window, for example, by clicking on the toolbar button