title: How do I access an instance of a class in Swift
body: <p>I have a user class defined in <code>UserClass.swift</code> like this:</p>
  
  <pre><code>class User {
      var id:Int
      var name:String
      var phone:String
      var email:String
  
      init(id:Int, name:String, phone:String, email:String){
          self.id = id
          self.name = name
          self.phone = phone
          self.email = email
      }
  }
  </code></pre>
  
  <p>In my <code>ProfileViewController</code> I call a method on <code>viewDidLoad</code> called <code>getUserData</code>.</p>
  
  <pre><code>class ProfileViewController: UIViewController {
  
      @IBOutlet weak var userNameLabel: UILabel!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          getUserData { myUser in
              self.userNameLabel.text = myUser.name
          }
  }
  </code></pre>
  
  <p><code>getUserData</code> pings my API and then instantiates and instance of the <code>User</code> class.</p>
  
  <pre><code>func getUserData(completionHandler:(User)-&gt;()) {
  
      Alamofire.request(.GET, "apiEndPoint")
          .responseJSON { response in
  
          if let value: AnyObject = response.result.value {
  
              let userData = JSON(value)
              let userName = userData["name"].string!
              let userId = userData["id"].int!
              let userPhone = userData["phone"].string!
              let userEmail = userData["email"].string!
  
              let myUser = User(id:userId, name:userName, phone:userPhone, email:userEmail)
  
              print("user: \(myUser.name)")
  
              completionHandler(myUser)
  
          }
      }
  }
  </code></pre>
  
  <p>I then pass that instance with a callback to the <code>ProfileViewController</code> so that I can update a label. This works great.</p>
  
  <p>The problem is that now I want to look at a different property of the <code>User</code> instance <code>myUser</code> in a different place, outside of the callback. Eventually I want to get the user's id, but for now I'm just trying to access the instance at all, so I'm looking again at updating a label with the user's name:</p>
  
  <pre><code>class MyActivitiesViewController: UIViewController {
  
      @IBOutlet weak var myActTempLabel: UILabel!
  
      override func viewDidLoad() {
          super.viewDidLoad()
              self.myActTempLabel.text = myUser.name
      }
  }
  </code></pre>
  
  <p>This is giving me an error of <code>Use of unresolved identifier 'myUser'</code>. How do I access the instance of User that I already created?</p>