Jack Sparrow Jack Sparrow - 2 months ago 30x
iOS Question

How to save response value to NSDictionary in Alamofire?

I'm using Alamofire v3.4.1 and i'm getting result of JSON via GET method like this,

@IBAction func verifyAction(sender: AnyObject) {

let tempEmail: String = "\(emailTxtField.text!)"
let tempApi : String = appDelegate.apiKey as String
var status : String
Alamofire.request(.GET, "http://www.somejsonurl.com/checkEmailExits", parameters: ["APIKey": "\(tempApi)","Email" : "\(tempEmail)"])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization

let JSON = response.result.value
let dict1 = JSON!["Result"]
let dict2 = dict1!!["Status"]
status = dict2 as! String


Now as soon as i assign value to
xcode gives me error:

Variable 'status' captured by a closure before being initialized

Is there a way to store response to
that can be used in other functions too ? Thanks


You need to initialize your object before assigning value to it so declare your status object like this

var status = String()


var status: String = ""