Providing a unified Swift error API
John Sundell

Great post! Thank you for sharing this idea :) I’m trying to utilise this concept a little bit more. Do you think this kind of function makes sense? It may be useful when converting from one ‘world’ of error handling to another.

func unwrap<T>(_ expression: @autoclosure () -> T?, 
orThrow error: Error) throws -> T {

guard let unwrapped = expression() else {
throw error
    return unwrapped
Show your support

Clapping shows how much you appreciated Krzysztof Kapitan’s story.