Swift4 TypecastingTypecasting is used in Swift4 to validate the type of an instance. It is used to check whether the instance type belongs to a particular super class or subclass or it is defined in its own hierarchy. Swift 4 type casting provides two operators:
To Define a Class HierarchyType casting is also used to check whether the instance type follows particular protocol conformance standard or not. It also checks hierarchy of classes, its subclasses and its instances to make it as a same hierarchy. Example:Output: Instance physics is: Mechanics Instance equation is: Hertz Instance physics is: Fluid Dynamics Instance formulae is: Giga Hertz How to do Type CheckingThe "is" operator is used to do type checking. It checks whether the instance belongs to particular subclass type and returns 'true' if it belongs otherwise returns 'false'. Next Topicfunction vs method in Swift |