Swift Object ModelLesson 31Free preview
Swift Extensions
This lesson is part of Swift · All levels
Summary
This lesson reviews Extensions in Swift that allow you to add new functionality to an existing class, struct, enum, or protocol type, even without having access to the original source code. Extensions can add computed properties, new methods, initializers, and make existing types adopt new protocols separately.
Key points
- Extensions extend existing types with the keyword 'NameType extension {...}'
- Can add computed properties (but not stored properties)
- You can add new methods, mutating methods, and convenience initializers.
- It is very popular for organizing code and adopting protocol separately (separation of concerns).
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.