是 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)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试了一些代码,但仍然没有解决我的问题。请帮助我,我是 swift 代码的新手。
let parameters: Parameters = ["skey": "XXXXXX","country_code":"91","mobile":"XXX004","user_role":"4"]
AF.request("http://XXXXX/dev/clinic/api/v1/login_otp?", method: .get, parameters: parameters)
.responseJSON { (response) in
switch response.result {
case .success:
if let JSON = response.result.value as? [String: Any] {
let status = JSON["status"] as! String
print(status)
}
case .failure(let error): break
// error handling
}
}
Run Code Online (Sandbox Code Playgroud)
下面是服务器响应
success({
message = "Otp sent successfully on +9170XXXX1004";
status = 1;
})
Run Code Online (Sandbox Code Playgroud)