Swift3.0 wrapper tool class based on AFNetworking

At the moment, I’m writing something for myself to learn swift3.0
to discover the pits. It’s been a long time since I looked at the underlying API based on a webView API

Swift3.0 wrapper tool class based on AFNetworking
Paste_Image.png

It’s kind of disgusting. The code is not difficult, but API’s change is really a headache. I believe OC is a total mess

Topic:
released its own simple a small package
online to find, as yourself more comfortable, so I wrote about
@escaping this note in the current study, how to use and swift3.0 in swift2.0, which changes. Also hope that God can guide one or two.

Import UIKit import AFNetworking enum HTResqustMethod: String case {Post = "post" case Get = "get" class NetworkTools: AFHTTPSessionManager let {static} shardTools {let: NetworkTools = tools = NetworkTools (tools.responseSerializer.acceptableContentTypes)?.insert (text/html) tools.responseSerializer.acceptableContentTypes?.insert (text/plain) return tools (func request (method:)} HTResqustMethod, urlString: String, parameters: AnyObject, resultBlock: @escaping ([String? Any]?, Error?) -> ()); / / to be executed after the closure of {/ / define a request for successful closure of let successBlock (task: URLSessionDataTask = {responseObj:, Any? In re) SultBlock (responseObj as? [String: Any], Nil)} / / failureBlock = {let failed closure (task: URLSessionDataTask, error: in? Error) resultBlock (nil, error)} / / Get request if method = =.Get {get (urlString, parameters: parameters, progress: nil, success: successBlock, failure: failureBlock)} / / Post request if method = =.Post {post (urlString, parameters: parameters, progress: nil, success: successBlock, failure: failureBlock)}}}

Here is the call

NetworkTools.shardTools.request (method:.Post, urlString: urlString, parameters: params as AnyObject?) {(responseObject, error) in if error! = nil {print} (error!) return guard (responseObject as? [String: AnyObject] = nil else{return)!}} print (responseObject!)