Recall & Review
beginner
What is an initializer in Swift?
An initializer is a special method that prepares an instance of a class, struct, or enum for use by setting initial values for its properties.
Click to reveal answer
intermediate
What is a designated initializer?
A designated initializer is the primary initializer for a class that fully initializes all properties introduced by that class and calls an appropriate superclass initializer.Click to reveal answer
intermediate
How does a designated initializer differ from a convenience initializer?
A designated initializer initializes all properties and calls a superclass initializer, while a convenience initializer provides shortcuts and must call another initializer from the same class.Click to reveal answer
intermediate
Why must a designated initializer call a superclass initializer?Because the superclass may have properties that need initialization, calling its initializer ensures the entire inheritance chain is properly set up.Click to reveal answer
beginner
What happens if you don’t provide any initializer in a Swift class?
Swift provides a default initializer if all properties have default values and no custom initializers are defined.
Click to reveal answer
Which initializer must fully initialize all properties introduced by its class?
✗ Incorrect
A designated initializer fully initializes all properties introduced by its class.
In Swift, a convenience initializer must call:
✗ Incorrect
Convenience initializers must call another initializer from the same class, usually a designated initializer.
What is the main role of a designated initializer in a class hierarchy?
✗ Incorrect
Designated initializers initialize all properties and call the superclass initializer to ensure proper setup.
If a Swift class has all properties with default values and no custom initializers, what initializer is available?
✗ Incorrect
Swift automatically provides a default initializer in this case.
Which of the following is true about designated initializers?
✗ Incorrect
Designated initializers must call a superclass designated initializer to ensure proper initialization.
Explain the difference between a designated initializer and a convenience initializer in Swift.
Think about who does the full setup and who provides easier ways to create instances.
You got /4 concepts.
Describe why calling a superclass initializer is important in a designated initializer.
Consider what happens if the superclass is not properly set up.
You got /3 concepts.