I’m still new in Swift development and I’m wondering how can I call This function with the status and results?
func getStatus(completion: @escaping (Swift.Result<SubscriptionStatus, MAPIError>) -> Void )
{
getStatus { result in
switch(result) {
case .success(let subscription):
switch(subscription.status) {
case .subscribed:
completion(.success(true))
default:
completion(.success(false))
}
case .failure(let error):
completion(.failure(error))
}
}
}
Many Thanks
Calling the function
2
Answers
Result is an enum which can be either:
success
or
failure
So,
completion(.success(value))
orcompletion(.failure(someError))
Result is such a powerful keyword in swift!
It determines wether the task should succeed or fail.
To complete your function you should call it like this:
If the task succeed
Or
To call your function you should do it like this:
Hope it helps!!