Alamofire4.4 在swift3 项目中的使用

最近刚接手swift3和OC混编的项目,项目比较乱,由于网络请求的工具类是上一个人基于AFN二次封装的,在swift中调用时很不方便而且容易出错,所以swift代码部分我打算使用swift的请求库,一来可以学习swift3;二来打算以后有时间把这个项目转型为swift项目

使用Alamofire4.4 发送 Post请求

        let postUrl =  "www.taobao.com"
        let param : [String : Any]? = ["userId" : userId]
       //  print(postUrl, "***", param!)

        SVProgressHUD.show()
        Alamofire.request(postUrl, method: .post, parameters: param , encoding: URLEncoding.default, headers: nil).responseJSON { (response ) in
            //
            SVProgressHUD.dismiss()
            
            //        print(response.result.isSuccess,"***",response.result.value!)
            guard  response.result.isSuccess else {
                SVProgressHUD.showError(withStatus: "服务器异常\n请稍后再试")
                return
            }
          
            guard let json = response.result.value else {
                print("json为空")
                return
            }
//            print(json)
            
            guard let dict = json as? [String: AnyObject] else {
                print("json转换字典失败")
                return
            }
            
            guard let subDict:Dictionary = dict["responseData"] as? [String: AnyObject] else {
                print("json转换字典失败")
                return
            }
            guard   let typeValue:NSInteger = subDict["type"] as? NSInteger else {
                return
            }
            self.typeV = typeValue
        // **************其他操作.............
        // ................................

}

你可能感兴趣的:(Alamofire4.4 在swift3 项目中的使用)