Skip to content

0.3.0

Latest

Choose a tag to compare

@meech-ward meech-ward released this 18 Mar 01:15

Removed different api for dealing with optionals

If you pass an optional value to mightFail, the first guard is for the error check, you'll need a second guard to see if you have a value.

func returnOptional() throws -> String? {
    return nil
}

let (error, result) = mightFail {
    try returnOptional()
}

// result is String??
guard let result else {
    // there was an error, handle it 
    print(error)
    return
}

guard let result else {
   // no error, but result is nil, handle it 
   print("No result")
   return
}

print(result) // "Success"