Tuesday, September 6, 2016 [Tweets] [Favorites]

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

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment