title: How do I refresh menu items in a Swift app?
body: <p>I have a menubar app and need to refresh one of the menu items when the user opens the menu.</p>
  
  <p>I have a function that pulls the current IP's being used by the machine and stores them in a variable: <code>addresses</code>. The menu is called via <code>override func awakeFromNib()</code>. We have a timer function that I've tried using to update the <code>addresses</code> variable, but can't figure out how to get the menu itself to update with the new data in the variable.</p>
  
  <p>I've tried using a <code>didSet</code> on <code>addresses</code> to update the variable, and I've added the function that updates <code>addresses</code> to a <code>Timer</code> function, but that doesn't update the menu, only the variable.</p>
  
  <p>Here's the code to load the menu:</p>
  
  <pre><code>override func awakeFromNib() {
      Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateProcessTimer), userInfo: nil, repeats: true)
  
      statusItem.menu = statusMenu
      statusItem.image = icon
  
      // get computer information
      let compInfo = ComputerInfo()        
      let addresses = compInfo.getIPAddresses()
      let compName = compInfo.getComputerName()
  
  
      // present the computer info
      if let computerNameMenuItem = self.statusMenu.item(withTitle: "computerName") {
          computerNameMenuItem.title = compName ?? "unknown"
      }
      if let computerIPMenuItem = self.statusMenu.item(withTitle: "ipAddress") {
          computerIPMenuItem.title = addresses
      }   
  }
  </code></pre>
  
  <p>As it stands, it sets the menu items when the app loads, but that's it. I'd like to find a way to update the <code>computerIPMenuItem.title</code> every time the user clicks the menu.</p>
  
  <p>--ADDITIONAL INFO--</p>
  
  <p>The menu class is an <code>NSObject, NSApplicationDelegate</code> that calls a <code>nib</code> file. In the <code>nib</code> we have a menubar with <code>NSMenuItem</code> place-holders with the titles referenced above as <code>computerName</code> and <code>ipAddress</code>. Not sure if that helps clarify why some of the traditional <code>override func</code> calls aren't working.</p>