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

fhity93d  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(204)

我正在将我的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)
          }
      }
  )

在Failure部分中,我得到了以下错误消息:

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

as '类型Error的值没有成员UserInfo'

nhaq1z21

nhaq1z211#

. .按照Larme的建议使用Alamofire或探索其他服务。Alamofire与AFNetworking相同,非常灵活。您只需在代码中做一个小的更改即可集成。Swift3,4不太支持AFNetworking。

相关问题