I'm working on login in my project and I'm using Alamofire request (swift 2.0) and I always get an error that I can't resolve.
Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo=... {NSErrorFailingURLKey=..., NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=...}
Here is my code:
func login(email: String, password: String, completionHandler: (user: User?, statusCode: Int?, error: NSError?) -> ()) {
let parameters: [String: AnyObject] = [
"email" : email,
"password" : password
]
let urlSuffix = "loginUser"
request(.POST, baseUrl + urlSuffix, parameters: parameters)
.authenticate(user: email, password: password)
.validate()
.responseObject { (request, response, userJSON: Result<User>) in
print(request?.description)
print(response)
print(userJSON.value)
completionHandler(user: userJSON.value, statusCode: response?.statusCode, error: userJSON.error)
}
}
I call that function in my LoginController, when user press a button.
I passed through many posts about that error, but none of them gave me a solution. The problem is, I need the response, a JSON object witch contains user's id. But my Result<User> is nil due to the error.