title: Change time interval of scheduler at run time
body: <p>Here is the code:</p>
  
  <pre><code>import Cocoa
  import Foundation
  
  @NSApplicationMain
  class AppDelegate: NSObject, NSApplicationDelegate {
  
      @IBOutlet weak var window: NSWindow!
  
  
      func applicationDidFinishLaunching(_ aNotification: Notification) {
          // Insert code here to initialize your application
          lbl.drawsBackground = true
          lbl.backgroundColor = NSColor.black
          Timer.scheduledTimer(withTimeInterval: 1.0/Double(hz * 2), repeats: true, block: toggleBackground)
      }
  
      var hz = 40
  
      func toggleBackground(_ timer: Timer) {
          if lbl.backgroundColor == NSColor.white{
              lbl.backgroundColor = NSColor.black
          } else {
              lbl.backgroundColor = NSColor.white
          }
      }
  
      func applicationWillTerminate(_ aNotification: Notification) {
          // Insert code here to tear down your application
      }
  
  
      @IBOutlet weak var lbl: NSTextField!
  }
  </code></pre>
  
  <p>Full project here: <a href="https://github.com/kindlychung/Flickalz" rel="nofollow noreferrer">https://github.com/kindlychung/Flickalz</a></p>
  
  <p>It's a simple app that changes the background color of a label at 80Hz. I would like to make that frequency customizable (through a text field or a slider) at run time but don't know how that may be done. Any ideas?</p>