SwiftUI: Open multiple windows on App start on macOS

1.1k views Asked by At

I'm trying to open two windows on App startup. One to show on another screen and the second to control the first window on my screen. Unfortunately I cannot get it running. I just tried to add a second WindowGroup, but it always just launches my first WindowGroup. I just read that this is the normal behaviour, but what is the correct way to open up two different windows on App startup?

import SwiftUI

@main
struct MyApp: App {
    
    var body: some Scene {
        WindowGroup("Test") {
            Text("Hello test")
                .frame(width: 1000, height: 1000, alignment: .center
                )
        }
        
        WindowGroup {
            ContentView()
                .frame(minWidth: 800, minHeight: 1000)
        }
    }
}
1

There are 1 answers

0
pipo92 On BEST ANSWER

I found the solution myself with help of this answer

Instead of putting the openURL part into a Button, just add it to the onAppear call of the ContentView.