我在与typealias完成处理程序有点困惑
我创建了一个typealias具有结果,状态数据。这里是我正在创建它:
typealias Success = (_ result:Dictionary<String, Any>, _ Status:Bool,_ Data:Data) -> Void
我有一个方法与URL,帕拉姆,故障警报和完成handler.I有typealias传递到完成处理器。这里是方法
private func callApi(apiURL:ApiURL, param:[String: Any]?, failAlert:Bool, completionHandler: @escaping Success) {
var url = "\(AppBaseUrl)\(apiURL.rawValue)"
var params:[String:Any] = [:]
var methods:HTTPMethod = .get
if param != nil {
params = param!
methods = .post
self.printParam(param: params)
}
self.apiCallKR(url: url, methods: methods, params: params, failAlert: failAlert, completionHandler: Success)
}
我得到的错误是这样
无法将类型“Success.Type”的值(又名“((词典,布尔,数据) - >())类型”
如何通过completionHandler(KRResult.result,KRResult.Status,response.data!)成功Typealias
func apiCallKR(url:String, methods:HTTPMethod, params:[String:Any], failAlert:Bool, completionHandler: @escaping Success) {
let header = ["User-ID":Extensions.getUserID(),"Auth-Key":Extensions.getToken()]
Alamofire.request(url, method: methods, parameters: params, encoding: URLEncoding.default, headers: header).responseJSON { (response) in
KRLog("Response: \n\(response)")
let statusCode = response.response?.statusCode
switch response.result {
case .success:
if statusCode == 200, let json = response.result.value as? [String: Any] {
AppDetail.stopIndicator()
let KRResult = self.jsonResponseValidation(sender: json, failAlert: failAlert)
completionHandler(KRResult.result, KRResult.Status,response.data!)
}else {
completionHandler([:], false, response.data!)
AppDetail.stopIndicator()
AppDetail.showToast(toastText: AlertText(.textAlertJsonFormatMismatch), type: .fail, handler: nil)
}
}
}
}
尝试
self.apiCallKR(url: url, methods: methods, params: params, failAlert: failAlert, completionHandler: completionHandler)