Recall & Review
beginner
What is a struct in Swift?
A struct is a value type that stores data and copies itself when assigned or passed around. It is often used for simple data containers.
Click to reveal answer
beginner
What is a class in Swift?A class is a reference type that stores data and shares the same instance when assigned or passed around. It supports inheritance and reference counting.Click to reveal answer
intermediate
How do structs and classes differ in memory behavior?
Structs copy their data when assigned or passed, so each variable has its own copy. Classes share the same instance, so changes affect all references.
Click to reveal answer
intermediate
Can structs inherit from other structs or classes?
No, structs cannot inherit from other structs or classes. Only classes support inheritance in Swift.
Click to reveal answer
beginner
When should you choose a struct over a class in Swift?Choose a struct when you want simple, safe data containers that copy on assignment and don’t need inheritance or shared state.
Click to reveal answer
Which of the following is true about Swift structs?
✗ Incorrect
Structs are value types and copy their data when assigned or passed. They do not support inheritance but can have methods.
What happens when you assign a class instance to a new variable?
✗ Incorrect
Classes are reference types, so assigning them copies the reference, not the data. Both variables point to the same instance.
Which feature is only available in classes but not structs?
✗ Incorrect
Only classes support inheritance in Swift. Structs cannot inherit from other types.
Why might you prefer structs for simple data models?
✗ Incorrect
Structs copy their data on assignment, so each variable has its own copy, which helps avoid bugs from shared state.
Which of these is NOT a characteristic of Swift classes?
✗ Incorrect
Classes do not copy data on assignment; they share references. Structs copy data on assignment.
Explain the main differences between structs and classes in Swift.
Think about how data is stored and shared.
You got /4 concepts.
When would you choose a struct instead of a class for your data model in an iOS app?
Consider safety and simplicity.
You got /4 concepts.