Recall & Review
beginner
What is a common limitation when using Swift's automatic reference counting (ARC)?
ARC can cause retain cycles if two objects hold strong references to each other, leading to memory leaks.
Click to reveal answer
beginner
Why should you avoid force unwrapping optionals in Swift?
Force unwrapping can cause runtime crashes if the optional is nil. It's safer to use optional binding or optional chaining.
Click to reveal answer
intermediate
What is a best practice when working with concurrency in Swift?
Use structured concurrency with async/await and avoid shared mutable state to prevent race conditions and improve code clarity.
Click to reveal answer
intermediate
What limitation does Swift have regarding dynamic dispatch for structs and enums?
Structs and enums use static dispatch by default, so you cannot override methods or use polymorphism like with classes.
Click to reveal answer
beginner
Why is it recommended to use value types (structs) over reference types (classes) when possible in Swift?
Value types provide safer code by avoiding shared mutable state and making data easier to reason about, improving performance and thread safety.
Click to reveal answer
What can cause a retain cycle in Swift's ARC system?
✗ Incorrect
Retain cycles happen when two objects hold strong references to each other, preventing ARC from deallocating them.
Which is the safest way to access an optional value in Swift?
✗ Incorrect
Optional binding safely unwraps optionals and avoids runtime crashes if the value is nil.
What is a recommended practice when writing concurrent Swift code?
✗ Incorrect
Structured concurrency with async/await and avoiding shared mutable state helps prevent bugs and race conditions.
Which Swift types use static dispatch by default?
✗ Incorrect
Structs and enums use static dispatch, meaning their methods are resolved at compile time.
Why prefer value types over reference types in Swift when possible?
✗ Incorrect
Value types avoid shared mutable state, making code safer and easier to reason about, especially in concurrent contexts.
Explain the main limitation of Swift's ARC and how to avoid it.
Think about how two objects can keep each other alive unintentionally.
You got /4 concepts.
Describe best practices for safely handling optionals and concurrency in Swift.
Focus on safety and clarity in your code.
You got /5 concepts.