Monday, June 29, 2020

as, as?, and as! in Swift

Ole Begemann:

as? and as! perform downcasting at runtime.

[…]

as? and as! are the same operation, the only difference being that as! force-unwraps its result.

[…]

In contrast, as coerces a value to a type at compile time.

[…]

A syntactic nuance: when using as in pattern matching contexts, the check is performed at runtime (it has to be).

Previously:

Comments RSS · Twitter

Leave a Comment