want to create global http request function/extension with Alamofire it's like
function Request(requestPath:String, requestParams:Any, onComplate:Void) {
// stuff here, when async request complate i want to call onComplate function
// like C# method.Invoke() or func.Invoke()
}
You can just pass the closure(function) as parameter
swift
func request(requestPath:String, requestParams:Any, callback:((Result) -> Void)) {
...
}
Where Result
will be the type of your response.
Thanks for reply but finally solution
class HttpRequest<Request, Response>
{
private var serviceBase:String = "http://192.168.1.1/api";
func request(path:String, model: Request, success: @escaping((_ response: [Response]?) -> ()), failure: @escaping ((_ error:String) -> ()) {
// code here..
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With