n my last projects I have been using alamofire and promisekit to connect to my web services Now I have a new version of both and when I create a request I get this error
Cannot convert value of type 'DataRequest' to closure result type 'Void'
this happens when I try to do this:
func CallOne() -> Promise<[String: AnyObject]>{
return Promise{
fullfil,reject -> Void in
return Alamofire.request(
url_api,
method: .get).responseJSON{
response in
switch(response.result){
case .success(let res):
let data = res as? [String: AnyObject]
fullfil(data!)
case .failure(let error):
reject(error)
}
}
}
}
and when I try to use this:
func CallTwo(email: String, phone: String) -> Promise<[String: AnyObject]>{
let params =
["email": email, "phone": phone]
return Promise{
fullfil,reject -> Void in
return Alamofire.upload(
multipartFormData: { MultipartFormData in
for (key, value) in params {
MultipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to: url_api, method: .post) { (result) in
switch (result){
case .success(let upload, _, _):
upload.responseJSON { response in
switch(response.result){
case .success(let res):
let data = res as? [String: AnyObject]
fullfil(data!)
case .failure(let error):
reject(error)
}
}
case .failure(let encodingError):
print(encodingError)
}
}
}
}
I get this error Unable to infer closure type in the current context
How can I solve that? thanks in advance
I solve this using
seal in
func CallOne() -> Promise<[String: AnyObject]>{
return Promise{
seal in
return Alamofire.request(
url_api,
method: .get).responseJSON{
response in
switch(response.result){
case .success(let res):
let data = res as? [String: AnyObject]
seal.fulfill(data!)
case .failure(let error):
seal.reject(error)
}
}
}
}
func CallTwo(email: String, phone: String) -> Promise<[String: AnyObject]>{
let params =
["email": email, "phone": phone]
return Promise{
seal in
return Alamofire.upload(
multipartFormData: { MultipartFormData in
for (key, value) in params {
MultipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to: url_api, method: .post) { (result) in
switch (result){
case .success(let upload, _, _):
upload.responseJSON { response in
switch(response.result){
case .success(let res):
let data = res as? [String: AnyObject]
seal.fulfill(data!)
case .failure(let error):
seal.reject(error)
}
}
case .failure(let encodingError):
print(encodingError)
}
}
}
}