由于最新的**Alamofire**网络框架只支持Swift 3.0, 现在还有一大部分开发者 在项目中用OC于Swift混编的方式,所以就用最新的Swift 3.0对AFNetworking3做了封装希望对大家有用
func request(requestType: RCRequestType, 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)
}
//POST
if requestType == .POST{
post(url, parameters: params, progress: nil, success: successBlock, failure: failureBlock)
}