Reputation: 2352
In AppDelegate.swift I've declared an NSStatusBar object like this:
var statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
statusItem.button?.title = "chess"
statusItem.button?.target = self
statusItem.button?.action = #selector(showSettings)
and works fine, but I want to change the title in the viewController.swift
I trying this (In view controller):
var appd = AppDelegate()
appd.statusItem.button?.title = "ELO: \(parsing2.chess_daily.last.rating)"
But the title not change... how can I do this???
Upvotes: 0
Views: 302
Reputation: 285059
Get the delegate object from NSApplication
, the default initializer AppDelegate()
creates a new unrelated instance.
let appDelegate = NSApp.delegate as! AppDelegate
appDelegate.statusItem.button?.title = "ELO: \(parsing2.chess_daily.last.rating)"
Upvotes: 1