Recall & Review
beginner
What is a key difference between classes and structs in Swift?
Classes support inheritance and reference semantics, while structs do not. Structs have value semantics, meaning each copy is independent.
Click to reveal answer
beginner
Why do classes exist alongside structs in Swift?
Classes exist to provide features like inheritance, reference sharing, and deinitializers, which structs do not support.
Click to reveal answer
beginner
What does it mean that structs have value semantics?
Value semantics means when you assign or pass a struct, a copy is made. Changes to one copy do not affect others.
Click to reveal answer
beginner
What is a real-life example to understand reference semantics of classes?
Think of a class instance like a shared remote control. Multiple people can use the same remote (reference), so changes affect all users.Click to reveal answer
beginner
Can structs in Swift have methods and properties?
Yes, structs can have methods and properties, but they cannot inherit from other types or have deinitializers.
Click to reveal answer
Which feature is unique to classes in Swift?
✗ Incorrect
Only classes support inheritance; structs do not.
What happens when you assign a struct to a new variable?
✗ Incorrect
Structs have value semantics, so assignment creates a copy.
Which of these is true about classes in Swift?
✗ Incorrect
Classes use reference semantics, so variables share the same instance.
Why might you choose a struct over a class?
✗ Incorrect
Structs are good when you want each copy to be independent.
Which feature do structs NOT support?
✗ Incorrect
Structs cannot have deinitializers; only classes can.
Explain why Swift has both classes and structs. What are the main differences and when would you use each?
Think about how data is shared or copied in your program.
You got /6 concepts.
Describe a real-life example that helps understand the difference between reference and value semantics in Swift.
Use everyday objects to explain how data sharing works.
You got /4 concepts.