Recall & Review
beginner
What is protocol conformance via extension in Swift?
It means adding the ability for a type to follow a protocol by writing the required methods or properties inside an extension, not in the original type definition.
Click to reveal answer
beginner
Why use extensions to conform to protocols in Swift?
Extensions help organize code by separating protocol requirements from the main type code, making it cleaner and easier to read.
Click to reveal answer
intermediate
Can you add stored properties in an extension to conform to a protocol?
No, extensions cannot add stored properties. They can only add computed properties, methods, or make a type conform to a protocol.
Click to reveal answer
beginner
Example: How to make a struct conform to a protocol using an extension?
Define the struct first, then create an extension for it that implements the protocol's required methods or properties.
Click to reveal answer
intermediate
What happens if a type already conforms to a protocol but you add conformance again in an extension?
Swift will give an error because a type can only conform to a protocol once. You can add methods in extensions but not duplicate conformance.
Click to reveal answer
What can you NOT add in a Swift extension to help conform to a protocol?
✗ Incorrect
Extensions cannot add stored properties, only computed properties, methods, or protocol conformance.
Why might you use an extension to conform to a protocol?
✗ Incorrect
Extensions help organize code by separating protocol conformance from the main type definition.
If a struct conforms to a protocol in an extension, where must the protocol methods be implemented?
✗ Incorrect
When conforming via extension, the required protocol methods must be implemented inside that extension.
Can a class conform to multiple protocols using multiple extensions?
✗ Incorrect
A class can conform to multiple protocols by using separate extensions for each protocol.
What error occurs if you try to declare the same protocol conformance twice for a type?
✗ Incorrect
Swift does not allow duplicate protocol conformance declarations for the same type.
Explain how protocol conformance via extension works in Swift and why it is useful.
Think about how extensions let you add features without changing the original type.
You got /3 concepts.
Describe the limitations of extensions when adding protocol conformance in Swift.
Remember what extensions can and cannot do compared to the original type.
You got /3 concepts.