Swift: Type Cast operator

A constant or variable may refer to an instance of a subclass behind the scenes. In order to downcast them to their specific subclass , we can use the type cast operator ( as? or as!). As the downcast to a specific subclass may not succeed, the type cast operator comes in two forms. as? returns a optional value that may  or may not be nil. as! operator forcefully unwraps the class type and may result in error if downcasting failed.

Leave a Reply