swift - OC与swift3.0混编的项目中使用AFN

swift - OC与swift3.0混编的项目中使用AFN,第1张

概述//使用方法 let parameters = ["key1" : 1, "key2" : 2] WBNetwork.shareInstance.request(requestType: .GET, url: port1, params: parameters, success: {(responseObj) in     print(responseObj!)     if responseOb

//使用方法

let parameters = ["key1" : 1,"key2" : 2]

WBNetwork.shareInstance.request(requestType: .GET,url: port1,params: parameters,success: {(responSEObj) in

print(responSEObj!)

if responSEObj?["code"] as? Int == 0 {

}

}) {(error) in print(error!) }


//工具类

import UIKit

enum RequestType {

case GET

case POST

}


class WBNetwork: AFhttpSessionManager {

static let shareInstance : WBNetwork = {

let tool = WBNetwork()

tool.responseSerializer.acceptableContentTypes?.insert("text/HTML")

//tool.responseSerializer.acceptableContentTypes?.insert("text/HTML" as AnyHashable)

return tool

}()

func request(requestType: RequestType,url : String,params: [String : Any],success: @escaPing([String : Any]?) ->(),failure: @escaPing( _ error : Error?) -> ()){

//成功

let successBlock = { (task: URLSessionDataTask,responSEObj: Any?) in

success(responSEObj as? [String : Any])

}

//失败

let failureBlock = {(task : URLSessionDataTask?,error:Error) in

failure(error)

}

//GET

if requestType == .GET {

get(url,parameters: params,progress: nil,success: successBlock,failure: failureBlock)

//get(url,failure: failureBlock)

}

//POST

if requestType == .POST {

post(url,0)"> //post(url,failure: failureBlock)

}

}

}

总结

以上是内存溢出为你收集整理的swift - OC与swift3.0混编项目中使用AFN全部内容,希望文章能够帮你解决swift - OC与swift3.0混编的项目中使用AFN所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1068954.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存