我正在使用 alamofire 和 swift 3。我想返回从 Http 请求中获得的数据。目前我正在使用完成处理程序来获取它。
func SendHttpRequest(params: AnyObject, header_obj: [String: String], url:String, http_method:HTTPMethod, completion: @escaping (_ response_value: JSON, _ error_type: String)->()) {
Alamofire.request(BASE_URL + url, method: http_method, parameters: (params as! [String : Any]) , encoding: URLEncoding.default, headers: header_obj).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case .success( _ ):
if let jsonValue = response.result.value {
let json = JSON(jsonValue)
completion(json, "")
}
break
case .failure(_):
print(response.result.error!)
completion(JSON(response.result.value!), "NO_INT")
//"The Internet connection appears to be offline."
break
}
}//Alamofire
}//SendHttpRequest
但我想要的是返回我通过 Http 请求获得的任何结果。例如:-
func GetUsers() -> [Users]{
//HERE IT SHOULD EXCUTE THE HTTP REQUEST AND RETURN THE USERS LIST
}
我怎样才能实现它?我可以像方法通过参数理论一样实现它吗?