Add new instance methods to existing types using Extension in Swift

Extensions add new functionality to an existing type. Type can be class, structure, enumeration or protocol. This includes the ability to extend types for which you do not have access to the original source code. Extensions in Swift can add computed instance properties and computed type properties. Extension helps to use more usable method by declaring it once in extension which means no need to redeclare and repeat same method in every class. Extension Syntax Declare extensions with the extension keyword: extension SomeType { // new functionality to add to SomeType goes here } This example adds method to Swift's build-in UIViewController type,