Sometimes, you need to provide extra capabilities to an object without modifying the object declaration. For this, we use extensions.
Here's what an extension looks like:
extension existingType : protocolName {
    property1
    property2
    property3
 
    method1()
    method2()
}
Let's look at how to work with extensions. You'll start by adopting a protocol via an extension.
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
                