Alamofire 5: Value of type 'Result' has no member 'value'

后端 未结 2 712
北海茫月
北海茫月 2021-01-11 20:12

Is the a new error in Alamofire 5? as this wasn\'t running into bugs last time. Below are the code which are done. Anyone who used Alamofire facing this?

imp         


        
相关标签:
2条回答
  • 2021-01-11 20:59

    You can also extract response it this way

    AF.request(url, method: HTTPMethod.get, parameters: param as? Parameters)
    .responseJSON { response in
          if let JSON = response.value {
              if response.response?.statusCode == 200{
                  completionHandler(JSON as AnyObject?, nil)
              }else if(response.response?.statusCode == 401){
                    completionHandler(JSON as AnyObject?, nil)
              }
          }
          else{
              if response.response?.statusCode == 401 {
                  SVProgressHUD.showInfo(withStatus: "Request timed out.")
              }
              else {
                  completionHandler(nil,response.error as NSError?)
              }
          }
     }
    
    0 讨论(0)
  • 2021-01-11 21:03

    You have to extract the result value as below,

    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)!)
                completion(try? SomeRequest(protobuf: value))
            case .failure(let error):
                print(error)
                completion(nil)
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题