Recall & Review
beginner
What does it mean that classes are reference types in Swift?
It means when you assign or pass a class instance, you are working with a reference to the same object in memory, not a copy. Changes affect the original instance.Click to reveal answer
beginner
How does assigning one class instance to another variable affect the objects?Both variables point to the same object. Changing the object through one variable changes it for the other too.
Click to reveal answer
intermediate
Compare classes and structs in Swift regarding value and reference types.
Classes are reference types (shared instance), structs are value types (copied on assignment).
Click to reveal answer
intermediate
What happens when you modify a property of a class instance passed to a function?The original instance is modified because the function receives a reference to the same object.
Click to reveal answer
advanced
Why is understanding reference types important when working with classes?
Because it helps avoid unexpected bugs from shared data and helps manage memory and object behavior correctly.
Click to reveal answer
In Swift, what happens when you assign one class instance to another variable?
✗ Incorrect
Classes are reference types, so assignment copies the reference, not the object.
Which of these is a reference type in Swift?
✗ Incorrect
Only classes are reference types; structs, enums, and tuples are value types.
If you change a property of a class instance inside a function, what happens outside the function?
✗ Incorrect
Functions receive a reference to the class instance, so changes affect the original.
Why might using classes lead to unexpected bugs?
✗ Incorrect
Shared references mean changes in one place affect all references, which can cause bugs.
Which statement is true about structs compared to classes in Swift?
✗ Incorrect
Structs are value types, so each assignment creates a copy.
Explain in your own words what it means that classes are reference types in Swift.
Think about what happens when you assign a class instance to a new variable.
You got /3 concepts.
Describe the difference between how classes and structs behave when assigned to new variables.
Consider what happens if you change a property after assignment.
You got /3 concepts.