The forced form, as!, attempts the downcast and force-unwraps the result as a single compound action. The conditional form, as?, returns an optional value of the type you are trying to downcast to. Where you believe this is the case, you can try to downcast to the subclass type with a type cast operator ( as? or as!).īecause downcasting can fail, the type cast operator comes in two different forms.
A constant or variable of a certain class type may actually refer to an instance of a subclass behind the scenes.