Recall & Review
beginner
What is a Swift extension?
A Swift extension lets you add new features to an existing class, struct, or enum without changing its original code.
Click to reveal answer
beginner
How do extensions add capability without modifying the original type?
Extensions add new methods, computed properties, or functionality separately, so the original type's code stays untouched and safe.
Click to reveal answer
beginner
Why is it useful that extensions don't modify original code?
It keeps the original code stable and lets you add features later, making your code easier to maintain and less error-prone.
Click to reveal answer
intermediate
Can extensions override existing methods in Swift?
No, extensions cannot override existing methods. They only add new functionality without changing existing behavior.
Click to reveal answer
beginner
Give a real-life example of why extensions are like adding new tools without changing the toolbox.
Imagine a toolbox you bought. Extensions are like adding new tools to the box without changing the tools already inside. You get more tools but the original ones stay the same.
Click to reveal answer
What can Swift extensions add to a type?
✗ Incorrect
Extensions can add new methods and computed properties but cannot add stored properties or change existing methods.
Why do extensions not modify the original type's code?
✗ Incorrect
Extensions add functionality separately, so the original code remains unchanged.
Which of these is NOT possible with Swift extensions?
✗ Incorrect
Extensions cannot add stored properties, only computed properties and methods.
What is a key benefit of using extensions?
✗ Incorrect
Extensions let you add features without modifying the original code, keeping it stable and clean.
If you want to add a new method to a struct without changing its source, what should you use?
✗ Incorrect
Extensions let you add new methods to structs without modifying their original source.
Explain in your own words why Swift extensions add capability without modifying the original type.
Think about how you can add new tools to a toolbox without changing the tools already inside.
You got /3 concepts.
Describe a situation where using an extension is better than changing the original code.
Imagine you want to add something new but don’t want to risk breaking what already works.
You got /3 concepts.