Tuesday, September 6, 2016

Swift 3’s “Never”

Erica Sadun:

SE-0102 removes the rarely-used @noreturn function type and replaced it with a dead-end return type[…]


Never allows a function or method to throw: e.g. () throws -> Never. Throwing allows a secondary path for error remediation, even in functions that were not expected to return.

As a first class type, Never works with generics in a way that the @noreturn attribute could not.

Erica Sadun:

Guard conditions require you to exit scope. Never mean you cannot return from your function. So, instead, add a simple do-scope layer[…]

Fortunately, I don’t think this sort of contortion is commonly needed.

Comments RSS · Twitter

Leave a Comment