From here I see that the proper Alamofire 2/Swift 2 syntax when dealing with a JSON response is:
Alamofire.request(.GET, URLString, parameters: ["foo": "bar"])
.responseJSON { request, response, result in
switch result {
case .Success(let JSON):
print("Success with JSON: \(JSON)")
case .Failure(let data, let error):
print("Request failed with error: \(error)")
if let data = data {
print("Response data: \(NSString(data: data, encoding: NSUTF8StringEncoding)!)")
}
}
}
How and where is the let JSON
defined? (From a Swift point of view.)
I see in a request extension that ResponseSerializer
returns .Success(JSON)
but why is the handler not defined like a usual function:
case .Success(JSON: AnyObject?) {
print("Success with JSON: \(JSON)")
}
or better yet:
case .Success(JSON: NSDictionary?) {
print("Success with NSDictionary: \(JSON)")
}