Download this icon and drag it into your Assets.xcassets
.
AppDelegate.swift
//
// AppDelegate.swift
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
lazy var statusItem: NSStatusItem = {
let item = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength)
if let button = item.button {
button.image = NSImage(named: "StatusBarButtonImage")
button.action = #selector(showMenu)
}
return item
}()
func applicationDidFinishLaunching(_ aNotification: Notification) {
// set up status item
let _ = self.statusItem
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
// MARK: Handle menu
func showMenu() {
debugPrint("show menu...")
}
}
That's the Gist of it. If you need to know more about how to present a menu or a window this guide may help you get further ahead.