title: Swift: Return Type JSON from function
body: <p>so I've got a function that needs to return a JSON object that is received from an API endpoint. For some reason, this function always returns nil, even though when I print the response.result.value, it contains the API response perfectly, and enters the if statement to assign to returnJSON. Would appreciate any input!</p>
  
  <pre><code>func storeContact(name: String, number: String, apiToken: String) -&gt; AnyObject? {
  
  var returnJSON: AnyObject?
  
  let contact = ["api_token" : apiToken, "name" : name, "number": number]
  
  Alamofire.request(.POST, "http://sample.app/api/v1/contact", parameters: contact, encoding: .JSON).responseJSON { (response) -&gt; Void in
  
      if let value = response.result.value {
  
          returnJSON = value
  
      }
  }
  
  return returnJSON
  
  }
  </code></pre>