Member-only story
Don’t return — NEVER in Swift
Not nil, not null
Prerequisites:
You will need to be familar with the basics of Swift and able to start a Playground (or similar)
Terminology
Never: a return type for a function (or closure, or method) that will never terminate
The source of this article
I began looking at **Combine** after a voiding it for some time. Hidden in one of WWDC19’s videos is the following code snippet for **Subscribers**
extension Subscribers {class Assign<Root, Input>: Subscriber, Cancellable {typealias Failure = Neverinit(object: Root, keyPath: ReferenceWritableKeyPath<Root, Input>)}}
Where we are told
‘Because in Swift there is no way to handle an error when you are just writing a property value, we set the failure type of assign to Never’
Wait, what are you talking about?
The documentation
Apple’s documentation to the rescue (sort of).
They describe `Never` as a return type for a function (or closure, or method) that…