由于最新的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,failure: failureBlock) }
demo地址:https://github.com/roycehe/Swift3-AFN-
原文链接:/swift/322577.html