Monday, June 29, 2020 [Tweets] [Favorites]

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

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

Leave a Comment