Michael Long
3 days ago

--

The load() example can be simplified tremendously if you just catch errors by type. No nesting or messy switch statements needed.

https://gist.github.com/hmlongco/d94dcea1f6997bf5d73932559b0ee22b

The mapError is far from elegant, from my perspective.

The onSuccess/onFailure methods are problematuc in that they also allow you to easily ignore errors, something that Swift in general frowns upon.

Checkout the last example in the gist for a better handler that at least makes apparent the fact that you're ignoring failure modes.

You did a great job presenting the concepts, but I'm not still convinced that Result is worth the... ah... results. ;)

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)