Swift 3 - How to define the callback function as parameter

advertisements

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.