title: Proper way to store and pass data between classes
body: <p>I have a Users class and Login class (in separate files) where data is initialised and obtained first in the Login class and then stored in the Users class for future use in other classes.  To make use of the variables from the Users class, it appears that I have to constantly initialise it which resets the values in the class. How can I obtain variables without constantly initialising?</p>
  
  <p><strong>What it is right now:</strong></p>
  
  <p>Data is received in Login.swift -> Data is passed to Users.swift -> Unable to display data stored in Users.swift in ViewController.swift</p>
  
  <p><strong>What I am looking for:</strong></p>
  
  <p>Data is received in Login.swift -> Data is passed to Users.swift -> Display data stored in Users.swift in ViewController.swift</p>
  
  <p><strong>Code in ViewController</strong></p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
  @IBOutlet weak var usernameLabel: UILabel!
  
  // var usernameLabelText = String()
  
  let dataObj = Users(Name: "", Email: "", Id: "", ProfilePicture: "", Username: "")
  
  var usernameLabelText: String? {
      return String(dataObj!.username)
  }
  
  override func viewDidLoad() {
      usernameLabel.text = "Welcome \(usernameLabelText)"
      print("This is the \(dataObj!.username)")
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  
  }
  </code></pre>
  
  <p><strong>Code in Login.swift</strong></p>
  
  <pre><code>import Foundation
  import Alamofire
  import SwiftyJSON
  class Login {
  
  var userName:String!
  var passWord:String!
  
  init(userName : String, passWord : String) {
  
      let parameters = [
          "username": userName,
          "password": passWord 
      ]
  
      Alamofire.request(.POST, "http://anyapi.com", parameters: parameters)
          .responseJSON { response in
              print(response.request)
              print(response.response)
              print(response.data)
              print(response.result)
              if let result = response.result.value {
                  print("Did receive JSON data: \(result)")
                  let value = JSON(result)
                  if let api_key = value["api_token"].string {
                      print("The token is " + api_key)
                  } else{
                      print("error parsing api token")
                  }
               //pass data to Users class
                 _ = Users.init(Name: value["name"].string, Email: value["email"].string, Id: value["id"].string, ProfilePicture: value["profile_picture"].string, Username: value["username"].string)
              }
              else {
                  print("JSON data is nil.")
              }
  
  
      }
  
  }
  }
  </code></pre>
  
  <p><strong>Code in Users.swift</strong></p>
  
  <pre><code>import Foundation
  import Alamofire
  import SwiftyJSON
  
  class Users {
  private var _name: String!
  private var _email: String!
  private var _userId: String!
  private var _profilePicture: String!
  private var _username: String!
  
  var particulars: [String] = []
  
  var name: String {
      _name = particulars[0]
      return _name
  }
  
  var email: String {
      _email = particulars[1]
      return _email
  }
  
  var userId: String {
      _userId = particulars[2]
      return _userId
  }
  
  var profilePicture: String {
      _profilePicture = particulars[3]
      return _profilePicture
  }
  
  var username: String {
        _username = particulars[4]
      return _username
  }
  
  
  required init?(Name: String?, Email: String?, Id: String?, ProfilePicture: String?, Username: String?) {
      particulars += ["\(Name)"]
      particulars += ["\(Email)"]
      particulars += ["\(Id)"]
      particulars += ["\(ProfilePicture)"]
      particulars += ["\(Username)"]
  }
  
  }
  </code></pre>