Menus and Popovers in Menu Bar Apps for macOS

Menus and Popovers in Menu Bar Apps for macOS

Update note: This Menus and Popovers in Menu Bar Apps for macOS tutorial has been updated to Xcode 9 and Swift 4 by Warren Burton. The original tutorial was written by Mikael Konutgan.

[…]

Fire up Xcode. Go to File/New/Project… then select the macOS/Application/Cocoa App template and click Next.

[…]

Once the new project is set up, open AppDelegate.swift and add the following property to the class:

[…]

Back in AppDelegate.swift, add the following code to applicationDidFinishLaunching(_:)

[…]

Go to File/New/File…, select the macOS/Source/Cocoa Class template and click Next.

[…]

Next add the following code to the end of QuotesViewController.swift

[…]

Now go back to AppDelegate.swift. Start by adding a new property declaration to the class:

[…]

First, you need a model to store the quotes and attributions. Go to File/New/File… and select the macOS/Source/Swift File template, then click Next. Name the file Quote and click Create.

Open Quote.swift and add the following code to the file:

[…]

Now open QuotesViewController.swift and add the the following code to the class implementation of QuotesViewController:

Add this extension after the class implementation. You will now have two extensions in QuotesViewController.swift.

[…]

Open QuotesViewController.swift and add the following properties to the class implementation:

[…]

Create a new Swift File and name it EventMonitor, and then replace its contents with the following class definition:

[…]