Chapter    9

Subclassing and Extending

As stated in the introduction to the previous chapter, Swift is predominantly a protocol-based language. That said, the Swift standard library utilizes extensions expansively to build out the capabilities of its classes, structures, and enumerations. Following suit, this design pattern should also be adopted in custom code. When it comes to expanding the capabilities of a class, however, a choice must be made whether to subclass or extend. Subclassing provides certain capabilities not possible with extensions. In this chapter, the capabilities afforded by subclassing and extending will be explored in Swift, compared to each other and their counterparts in Objective-C.

Subclassing

Subclassing is a core tenet ...

Get Transitioning to Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.