Swift: Creating statusbar and menu items

Swift is the new programming language of Apple. It will give Objective-C a hard time.

Below an example how to add a status item to the statusbar, with a menu and items.

func applicationDidFinishLaunching(aNotification: NSNotification?) {  
        let bar = NSStatusBar.systemStatusBar()

        statusItem = bar.statusItemWithLength(CGFloat(NSVariableStatusItemLength))
        statusItem!.title = "Menu"
        statusItem!.highlightMode = true
        statusItem!.menu = NSMenu()

        var newItem : NSMenuItem = NSMenuItem(title: "Quit", action: Selector("Quit:"), keyEquivalent: "")
        statusItem!.menu.addItem(newItem)      
        statusItem!.menu.addItem(NSMenuItem.separatorItem())
    }

    func Quit(send: AnyObject?) {
        NSLog("Exit")
        NSApplication.sharedApplication().terminate(nil)
    }

References