I am trying to grab the response after making a post request and store that into a variable in this fashion:
var databaseId:String = ""
Alamofire.request(url, method: post, parameters: paramters).responseJSON { response in
let jsonData = JSON(data: response.data!)
self.databaseId = jsonData["id"].stringValue
//databaseId has the right value in here but when I try to use it out side of this request it does't retain its value
}
print(databaseId) //will be ""
I understand why this is happening. The request is still being made at the time this print statement is being executed so it is still set to its default value. Is there a work around anybody has figured out for this? I've tried using completion handlers, enclosing the request body in a main thread block, but nothing works. If anybody knows a solution I would really appreciate it.