Reputation: 1588
I have a protocol/function in my class which is below,
func getMovieList(completionHandler: @escaping (Result<[String], Error>) -> Void) { }
When the above method is called, I want to store the completion handler and call the success/error in the latter part.
I tried creating a typealias like below,
typealias AlbumListCompletionHandler = (((Result<[String], Error>)) -> Void)?
And in my class,
var completionHandlerObj: AlbumListCompletionHandler
func getMovieList(completionHandler: @escaping (Result<[String], Error>) -> Void) {
completionHandlerObj = completionHandler
/...
.../
}
But I wonder how do I call the success/error blocks in completionHandlerObj, kind of struck here. Can anyone help me with this ?
Upvotes: 1
Views: 744
Reputation: 780
It should work like this
completionHandlerObj(.success(["",""]))
completionHandlerObj(.failure(ErrorObject))
Upvotes: 1