TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Confused about Window and WindowGroup

Forums > macOS

I'm being a bit thick. I know I can create a Mac app and, in the top level scene, I can create a WindowGroup for my ContentView. That works fine. However, I can replace the WindowGroup with a plain Window and that works just as well. So why do I need two components?

I've read the description of WindowGroup several times but it doesnt help. It's technically accurate and tells me what it is, but not why its different from a Window or why I should use it in preferance to a Window.

What is it that WindowGroup gives me that Window doesn't?

Sorry if this is a bit basic. When I Google information on WindowGroup I tend to get the Apple docs regurgitated as though it is blindingly obvious what it means. That either means it's blindingly obvious or that other people can't define the difference either!

Thanks in advance. Steve


However, I can replace the WindowGroup with a plain Window and that works just as well. So why do I need two components?

Can you open several windows of the app at the same time just using Window?

As far as I understand with WindowGroup you can open several windows of the same app. Logically, just using Window you can open just one window of the app...

“SwiftUI includes several structures to create standard Scenes for every system. The currently available are WindowGroup, Window, DocumentGroup, Settings, and MenuBarExtra. Some of these structures are designed to create Scenes for Mac computers, as we will see later, and others are more generic. For instance, the WindowGroup structure can manage multiple windows for iPhones, iPads and Macs, and therefore it is the one recommended for most projects.”

Excerpt From SwiftUI for Masterminds 3rd Edition 2022 J.D. Gauchat


If I use Window, I get one main window for my app. From there I can open other windows, but I still have only one main window. I'll checkout SwiftUI for Masterminds to see if they go into more detail.

Thank you.


Ah, I see, when I specify Window as the top level component, I will only ever get one top level window. If I use WindowGroup, a menu item will be generated for me (File -> New Window) that creates another instance of the top level window. I also have a window-specific close menu item.

I suspect it's doing more for me than that, but it makes sense that it's managing multiple top level windows.



Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.