'SwiftUI WindowGroup: How to limit the number of windows?

I am building a single window application and want to use the new Swift App Lifecycle.

import SwiftUI

@main
struct SingleWindowApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

The default implementation of WindowGroup allows multiple instances of the window (i.e. if you hit ⌘N). I wasn’t able to find a modifier that changes that behaviour.

How would I limit the number of windows within a WindowGroup to just 1?



Solution 1:[1]

As i was facing the same problem, but on iPad where the command modifier has no effect, I found this: There's an "Application Scene Manifest" UIApplicationSceneManifest property in your Info.plist that is a dictionary and as a child "Enable Multiple Windows" UIApplicationSupportsMultipleScenes which is set to YES by default. Settings this option to NO gives the desired effect :)

Info.plist for disabling multiple window support

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 warly