title: Swift: Updating a label from a second view controller
body: <p>I have two view controllers. I also have a universal variable called <code>number</code>. The first view controller has a label on it called <code>mainLabel</code>. My second view controller has a button on it. When the button is pressed it should subtract 200 from the variable <code>number</code> then update the <code>mainLabel</code> label. I can not figure out how to make <code>mainLabel</code> a label that works on the second view controller too.</p>
  
  <h3>First View Controller</h3>
  
  <pre><code>import UIKit
  
  var number:Int = 0
  
  class ViewController: UIViewController {
  
      @IBOutlet weak var mainLabel: UILabel!
  
      @IBAction func backgroundButton(sender: AnyObject) {
  
          number = number + 1
  
          mainLabel.text = "\(number)"
  
           NSUserDefaults.standardUserDefaults().setObject(number,     forKey: "number")
  
      }
  
     override func viewDidLoad() {
          super.viewDidLoad()
  
          if NSUserDefaults.standardUserDefaults().objectForKey("number")     != nil {
  
              number =     NSUserDefaults.standardUserDefaults().objectForKey("number") as! Int
  
          }
  
          mainLabel.text = "\(number)"
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
   }
  </code></pre>
  
  <h3>Second View Controller</h3>
  
  <pre><code>import UIKit
  
  class SecondViewController: UIViewController {
  
      @IBOutlet weak var buy1Label: UILabel!
  
      @IBAction func buy1(sender: AnyObject) {
  
          number = number - 200
  
          buy1Label.text = "Bought!"
  
          mainLabel.text = "\(number)"
  
      }
  
  }
  </code></pre>