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 […]
Type casting is used to check the type of an instance , to check whether a type conform to a protocol or to treat that instance as a different superclass or subclass from somewhere else in its own class hierarchy. Type casting in Swift is done by using is and as operators.