title: Swift Alamofire SwiftyJSON Asynchronous/Synchronous Class Methods
body: <p>So I currently have the following:</p>
  
  <pre><code>class ViewController: UIViewController {
  
  class Identity{
      let baseUrl = "superSecretURL"
      var _username: String = ""
      var _password: String = ""
      var _apiKey: String = ""
  
      init(){
  
      }
  
      init(username: String, apiKey: String){
          _username = username
          _apiKey = apiKey
      }
  
      init(username: String, password: String){
          _username = username
          _password = password
      }
  
      func loginPassword() -&gt; String{
          var loginJSON = ["auth": ["passwordCredentials": ["username": _username, "password": _password]]];
          var returnJSON: String
  
          request(.POST, baseUrl, parameters: loginJSON, encoding: .JSON)
              .responseJSON { (request, response, data, error) in
                  if let anError = error
                  {
                      // got an error in getting the data, need to handle it
                      println("error calling POST on /posts")
                      println(error)
                  }
                  else if let data: AnyObject = data
                  {
                      // handle the results as JSON, without a bunch of nested if loops
                      let post = JSON(data)
                      // to make sure it posted, print the results
                      println("JSON Returned")
                  }
          }
      }
  }
  
  var i = Identity(username: "secretName", password: "complicatedPassword")
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
  
      println("Before Call")
  
  
  
      println("After Call")
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  
  }
  </code></pre>
  
  <p>Basically I would like to be able to call the println("Before Call") then receive a response from the loginPassword() method and then println("After Call"). This is I believe synchronous but I can't figure out a way to get it to work and the whole threads thing has baffled my head.</p>
  
  <p>I basically want to be able to say:</p>
  
  <pre><code>if i.loginPassword(){ // do some login stuff }else{ // do some error stuff }
  </code></pre>
  
  <p>Any help or pointers appreciated.</p>