as, as?, and as! in Swift
as?andas!perform downcasting at runtime.[…]
as?andas!are the same operation, the only difference being thatas!force-unwraps its result.[…]
In contrast,
ascoerces a value to a type at compile time.[…]
A syntactic nuance: when using
asin pattern matching contexts, the check is performed at runtime (it has to be).
Previously:
- Swift Bridging of allHeaderFields
- NetService NutHouse
- Swift Subclass of NSTextStorage Is Slow Because of Swift Bridging
- Swift 4: Bridging Peephole for “as” Casts