Swift3:将失败块从 Swift2 转换为 Swift3 的 AFNetworking 问题

用户6159419

我正在将我的 Swift2 代码转换为 Swift3。

Swift2 中的代码

manager.post(url, parameters: dict,
      success: { (operation: AFHTTPRequestOperation?, responseObject: Any?) in
          self.removeActivityIndicator()                    
          
          if let jsonDict = self.parseJSON(responseObject) {
              callback(jsonDict)
          }
      },
      failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
          self.removeActivityIndicator()
          
          print("Error: " + error.localizedDescription)
          var dict = error.userInfo
          dict["error"] = error.localizedDescription
          if let jsonDict = dict as? Dictionary<String, AnyObject> {
              callback(jsonDict)
          }
      }
  )

在失败部分,我收到以下错误消息,

Cannot convert value of type '(AFHTTPRequestOperation!, NSError!) -> ()' to expected argument type '((AFHTTPRequestOperation?, Error?) -> Void)!'

当我转换failure: { (operation: AFHTTPRequestOperation!, error: NSError!)failure: { (operation, error)

我在线时出错

var dict = error.userInfo

因为“错误类型的值没有成员 UserInfo”

穆萨布·泽尚

. . 按照 Larme 的建议使用 Alamofire 或探索其他服务。Alamofire 与 AFNetworking 相同,非常灵活。您将在代码中进行细微的更改。Swift3,4 对 AFNetworking 的支持并不多。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章