Cocoa NSStatusItem has no button property

Hey, I'm creating an NSStatusItem but I can't access the button, it crashes if I unwrap it.

import Cocoa

func main() {
    let delegate = AppDelegate()
    let app = NSApplication.shared
    app.delegate = delegate
    app.setActivationPolicy(.prohibited)
    app.run()
}

final class AppDelegate: NSObject, NSApplicationDelegate {    

    var item: NSStatusItem!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        item = NSStatusItem()
        item.behavior = [.removalAllowed, .terminationOnRemoval]
        item.button!.image = NSImage(named: "circle.fill") // Crashes here
    }

}
Answered by TeamPuzel in 742171022

Nevermind I used it incorrectly, I needed to get a system status bar instance.

Accepted Answer

Nevermind I used it incorrectly, I needed to get a system status bar instance.

Cocoa NSStatusItem has no button property
 
 
Q