Understanding extensions

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.26.176