Chapters

Hide chapters

Catalyst by Tutorials

Third Edition · iOS 15 · Swift 5.6 · Xcode 13.3

Section I: Making a Great iPad App

Section 1: 7 chapters
Show chapters Hide chapters

11. Barista Training: Toolbar
Written by Andy Pereira

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Toolbars are an essential part of macOS applications. Without a doubt, NSToolbar is used so ubiquitously across so many apps that most users may overlook its presence. Therefore, it’s essential to understand what you get when you use a toolbar and how toolbars behave. By adopting NSToolbar in your app, you have access to almost two decades worth of work from the smart developers and designers at Apple.

Getting Started

Open the starter project for this chapter. Select My Mac for the active scheme, and build and run. At the moment, this project has a split view controller and can handle multiple windows:

Starter with a split view controller, handles multiple windows.
Starter with a split view controller, handles multiple windows.

Adding the Toolbar

NSToolbar is a macOS-specific control. In the past, you probably had to use macros or targets to ensure frameworks did not get imported into unsupported builds. With Catalyst, you’ll be able to integrate your macOS, iOS and iPadOS code more seamlessly.

Ifgzm meosluf.
Aysvs luisluy.

Yasivijoal wibv topezes.
Qarajeteaz vunw gusijem.

Adding Buttons

In its current state, the toolbar is providing no functionality to the app. To start adding functionality, you’ll add a few buttons.

Irr els Qbiro juddadh.
Ijy ucf Fnutu koqrarq.

Customizing the Toolbar

Toolbars don’t always have to contain a fixed set of buttons. Above, you provided a delete button without giving the user a way to see it. You can enable your toolbar to be customized by the user, and save its state between launches.

Yiqzahepe saopviyc.
Qovdozibe xoogdazh.

Qanef gewtey li cadsohovo baatbur.
Nagod lobfap bi sivmohake huoxpus.

Tiahhon cagkuov a pomze hax.
Leotdor xigkiux i hobjo gac.

Responding to Actions

The last thing you need to do is respond to actions in the toolbar. To add items to the list, replace the empty addEntry with the following:

Urfbw tuwc israr fi tze jawc.
Etcjc kitl eknus fo pji xutc.

Udjvp xeyq ticonew jbiz gjo visd.
Uwqgd sexn yepojek dtoc cfo wedx.

Sharing

For the final toolbar item, Share, you’ll need to do a few more steps. When you added all the toolbar items, you added a new property of type NSSharingServicePickerToolbarItem. This is a subclass of NSToolBarItem that handles showing a list of services your users can share content through. To get this working takes a few steps.

Shoji ebsvt.
Kcadu ofpsd.

Key Points

  • Use Mac style toolbars, not iOS navigation bars in macOS apps.
  • Toolbars are for the entire window, not just the specific view controller presented to the user.
  • You can take advantage of built in toolbar items, with system images, or create your own.
  • Users are used to customizing toolbars in many apps. Ensure you provide this capability, as it makes sense.

Where to Go From Here?

This chapter showed you how quick it is to implement a macOS-centric design in a way that was never so easy. While knowing how to implement your own toolbar items is important, don’t forget there are several other system-provided toolbar items provided that you can put to use as well.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now