Programmatically open a new Window in SwiftUI on macOS Ventura (13)

Mark van Wijnen
7 min readJul 11, 2022
Photo by Alesia Kazantceva on Unsplash

Since macOS Big Sur(11) we are able to open new windows using the URL scheme, but with the arrival of macOS Ventura (13) we finally have a way to do it programmatically.

In this story I am going to show you how by building a note taking app called Scribble. Every note, ‘scribble’, can be opened in a new window when you right click on it and choose the Open in new window option from the context menu. I am going to show you the different approaches.

Create the Scribble entity and conform to Identifiable by having an id.

Create the data storage DataStore object which will hold our scribbles in memory. In a real app you really want to look at a persistent storage instead.

It also contains a convenience function that will fetch the index of the scribble in the array using its identifier.

Create the structure and behavior of the app in ScribbleApp. It will contain a reference to our data store. This will be passed to our ContentView through the environment.

The hierarchy that you declare as the WindowGroup’s content serves as a template for each window that the app creates from that group. For more information visit Apple’s documentation about WindowGroup.

This is the first interface that we are going to build and expand. What you see is a NavigationSplitView that will have a collapsable navigation at the left side and a detail view at the right side where we will be able to view and edit our scribbles in the future. In the toolbar you will see a (+) button that will create a new scribble.

Mark van Wijnen

macOS/iPadOS/iOS/watchOS/visionOS developer and SwiftUI enthousiast. “Stay Hungry, Stay Foolish!” — Steve Jobs