If you have created a multi-window app in SwiftUI for macOS, the tabs come for free. The next question is how to add a new system menu command to open a new tab programatically.

the final product

Here is the code that adds a new command to the menu. It opens a new tab when users click on it or presses “Command+T”.

Credits, references


Final product

Here is the final product of what is this post about: implement a multi window app on macOS where each window has its own state while the state is accessible from the system menu.

Use case

We have implemented Multi window SwiftUI app using StateObject. That enabled the app to have…


ObservedObject

The @ObservedObject does not bind the ObservableObject to the view where it is defined. That means that when we change a value in one view, it is going to be propagated between the views as well.

Here is the code to make views with the shared state.


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn what are arrays in programming in this article.

Array

An array is a special type of variable that can hold multiple values.

Imagine…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn how to use another fundamental building block in programming, called conditional statements (a.k.a if/else branches).

Conditional (if/else) Statements

The if/else statement executes a block of…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn what is a boolean variable and how to work with it in this article.

Boolean variables

Boolean variables can be assigned only one of…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn various ways to define and work with string variables in this article.

Text/String variables

Text variables are called string variables in programming. String and…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn how to define and work with numeric variables.

Numeric variables

The numeric variables can be whole numbers or decimal numbers. Let’s define a whole…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn what are the primitive types in Javascript.

Variable Types

There is a couple of primitive types in JavaScript. …

Ondrej Kvasnovsky

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store