Pick the fix
Structs and classes both need a describe() method with a shared default. Which approach?
Hint 1 of 1
Which option works for structs?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A protocol with describe() as a requirement plus a default in a protocol extension
Correct. Any type can conform and override.
Why not the others?
- B A base class with
describe()that calls fatalError unless overridden. Structs can't inherit, and mistakes only show at runtime. - C Copy the method into each type. Duplication, with no shared contract.
- D An @objc protocol with an optional requirement. @objc protocols work only with classes.