title: How to reference UILabel strong reference programmatically using Swift?
body: <p>Using Swift, I have a UILabel that was created programmatically in the viewDidLoad override function:</p>
  
  <pre><code>var middleDate = UILabel(frame: CGRect(x: (screenWidth / 2) - 45, y: 0, width: 90, height: 20))
      middleDate.text = "3:13:46 PM"
      middleDate.font = UIFont(name: "ArialMT", size: 13)
      middleDate.textAlignment = .Center
  </code></pre>
  
  <p>Which works great.</p>
  
  <p>Then I am trying to change the text in the override function <code>viewDidAppear</code>.
  I get Build Failed with the message <code>Use of unresolved identifier 'middleDate'</code></p>
  
  <p>If I use interface builder and drag and drop a UILabel on the view, then give it a strong reference it works great. Is there a way to reference a programmatically created object with a strong reference?</p>
  
  <p>Or am I going about this incorrect?</p>
  
  <hr>
  
  <p>This is what I have on my ViewController.swift: </p>
  
  <p>I have a feeling that there is a much better and cleaner way to do this.</p>
  
  <pre><code>override func viewDidLoad() {
  
      super.viewDidLoad()
  
      var middleDate = UILabel(frame: CGRect(x: (screenWidth / 2) - 45, y: 0, width: 90, height: 20))
      middleDate.text = "3:13:46 PM"
      middleDate.font = UIFont(name: "ArialMT", size: 13)
      middleDate.textAlignment = .Center
  
      self.myTopView.addSubview(middleDate)
  }
  
  override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)
  
      var timer = NSTimer.scheduledTimerWithTimeInterval(1.0,
          target: self,
          selector: Selector("getLocalTime:"),
          userInfo: nil,
          repeats: true)
  
      let mainLoop = NSRunLoop.mainRunLoop()
      mainLoop.addTimer(timer, forMode: NSDefaultRunLoopMode)
  
      func getLocalTime(timer: NSTimer) { 
  
          var todaysDate:NSDate = NSDate()
          var dateFormatter:NSDateFormatter = NSDateFormatter()
          var centerDateFormatter:NSDateFormatter = NSDateFormatter()
  
          dateFormatter.dateFormat = "h:mm:ss"            
  
          var DateInFormat:String = dateFormatter.stringFromDate(todaysDate)            
  
          middleDate.text = "hello"
  
  
      }
  }
  </code></pre>