Reputation: 3
I am newbie and I have an error that I don't know how to fix, so I would appreciate all the helps. I am migrating from swift 2 to swift 3 and I get this error:
Expression type 'DataRequest' is ambiguous without more context
Here is my code:
static func renewToken(_ onSuccess: @escaping (JSON) -> Void, onFailure: @escaping (NSError) -> Void) {
let token = DataManager.token?.token
let header = ["Authorization": "Bearer "+token!]
Alamofire.request("\(BASE_URL)\(RENEWTOKEN_PATH)", method: .get, parameters: nil, encoding: .JSONEncoding.default, headers: header)
.validate()
.responseJSON { response in
switch response.result{
case .Success(let jsonObj):
onSuccess(JSON(jsonObj))
case .Failure(let error):
onFailure(error)
}
}
}
Upvotes: 0
Views: 1771
Reputation: 72410
Your error is misleading you need to make 3 changes with your code.
.JSONEncoding.default
but simply JSONEncoding.default
Alamofire 4.*
and Swift 3.*
case .Success
and .Failure
of Result enum
is now write in lowercase like .success
and .failure
.Error
instead of NSError
.So whole code goes like this.
static func renewToken(_ onSuccess: @escaping (JSON) -> Void, onFailure: @escaping (Error) -> Void) {
let token = ""
let header = ["Authorization": "Bearer "+token]
Alamofire.request("", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: header)
.validate()
.responseJSON { response in
switch response.result{
case .success(let jsonObj):
onSuccess(JSON(jsonObj))
case .failure(let error):
onFailure(error)
}
}
}
Upvotes: 1