Understanding the Result Type in Swift
Published on
Error handling when expecting a result out of an operation is a very common thing to do. For this reason, various high-level programming languages have introduced a Result
type into their libraries, on top of their existing error-handling features. This feature was implemented in Swift 5.
A Result
wraps a success or a failure. It is essentially an enum
with two possible cases: .success
and .failure
. The .success
case wraps the correct result of an operation, whereas a .failure
wraps an Error
. Its implementation uses generics, so you always know what you are going to get back.