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 is a core tenet ...