Alamofire 5中是否有新错误?因为这上次没有遇到错误。下面是完成的代码。任何使用Alamofire的人都面对过吗?
import Foundation
import Alamofire
class MyAppService {
static let shared = MyAppService()
let url = "http://127.0.0.1:5000"
private init() { }
func getCurrentUser(_ completion: @escaping (SomeRequest?) -> ()) {
let path = "/somePath"
AF.request("\(url)\(path)").responseData { response in
if let data = response.result.value { //error shown here (Value of type 'Result<Data, AFError>' has no member 'value')
let contact = try? SomeRequest(protobuf: data)
completion(contact)
}
completion(nil)
}
}
}
您必须按如下所示提取结果值,
func getCurrentUser(_ completion: @escaping (SomeRequest?) -> ()) {
let path = "/somePath"
AF.request("\(url)\(path)").responseData { response in
switch response.result {
case .success(let value):
print(String(data: value, encoding: .utf8)!)
let contact = try? SomeRequest(protobuf: value)
completion(contact)
case .failure(let error):
print(error)
completion(nil)
}
}
}
}