Kidfund / building.kid.fund

Kidfund's Design & Engineering blog
http://building.kid.fund/
Other
1 stars 2 forks source link

Short blog post: Converting ObjC exceptions to Swift errors #11

Open mrh-is opened 6 years ago

mrh-is commented 6 years ago

I combined this SO answer with this blog post so the block can return a generic something. Header & implementation here. Use like:

if let foo = try? ObjCException.try({
        return funcThatThrowsObjCException()
    }) {
    print(foo)
}

// or

do {
    let foo = try ObjCException.try(funcThatThrowsObjCException)
    print(foo)
} catch {
    print(error)
}