Conditional Downcasting Operator
🚧 Status: The conditional downcasting operator
as?
is implemented, but it only supports values that have the typeAnyStruct
andAnyResource
.
The conditional downcasting operator as?
can be used to type cast a value to a type. The operator returns an optional. If the value has a type that is a subtype of the given type that should be casted to, the operator returns the value as the given type, otherwise the result is nil
.
The cast and check is performed at run-time, i.e. when the program is executed, not statically, i.e. when the program is checked.
Downcasting works for nested types (e.g. arrays), interfaces (if a resource interface not to a concrete resource), and optionals.
Last updated