Alamofire 4.4.0 swift3.0

用的是swift3.0封装的是 Alamofire 4.4.0 版本


import UIKit
import Alamofire

// 定义请求方式
enum MethodType{
    case GET
    case POS    
}

class NetWorkTools {

    class func RequestData(type:MethodType,URLString:String,parameters:[String:NSString]? = nil,SuccessCallBack:@escaping(_ Success:AnyObject)->(),FalseCallBack:@escaping (_ false:AnyObject)->()){
    
        //1. 获取类型
        let method = type == .GET ? HTTPMethod.get: HTTPMethod.post
        
        // post 请求
        Alamofire.request(URLString, method: method, parameters: parameters).responseJSON { (response) in
            
            guard let result =  response.result.value else{
                // 请求失败
                FalseCallBack(response.result.error as AnyObject)
                return
            }
           // 请求成功
            SuccessCallBack(result as AnyObject)
        }
    }
}

GitHub:https://github.com/tianbinbin/Alamofire_- 喜欢的请点个赞

你可能感兴趣的:(Alamofire 4.4.0 swift3.0)