Programmatically open a new Window in SwiftUI on macOS Ventura (13)
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…