In Swift PromiseKit library there's Alamofire example using a bit strange syntax:
func login(completionHandler: (NSDictionary?, ErrorProtocol?) -> Void {
Alamofire.request(.GET, url, parameters: ["foo": "bar"])
.validate()
.responseJSON { response in
switch response.result {
case .success(let dict):
completionHandler(dict, nil)
case .failure(let error):
completionHandler(nil, error)
}
}
}
response
is an Alamofire enum describing two cases with associated values:
public enum Result<Value> {
case success(Value)
case failure(Error)
(...)
What I don't get is what does let
mean in each case:
line and where does the dict (or error) come from? Is this syntactic sugar for something more verbose but less confusing?