O'Reilly logo

Learn Swift 2 on the Mac, Second Edition by Waqar Malik

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    14

Extensions

When you write object-oriented programs, you’ll often want to add some new behavior to an existing class. For example, you might have designed a new kind of tire, so you’d subclass Tire and add the new, cool stuff. When you want to add behavior to an existing class, you often create a subclass.

But sometimes subclassing isn’t convenient. For example, to add some new behavior to String, you can sublass the string as your own string type such as MyString, but what if you’re using a toolkit or library they will have no knowledge of this new new class. When the toolkit or library return a string it will be returned as the original string type, you will end up converting those String type to MyString every time if you wanted ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required