//使用方法
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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)