Recall & Review
beginner
What is the purpose of the
Sendable protocol in Swift?The
Sendable protocol marks types as safe to be used across different threads without causing data races or undefined behavior.Click to reveal answer
intermediate
How does Swift check if a type conforms to
Sendable?Swift uses compile-time checks to ensure that all stored properties of a type are also
Sendable, making the whole type safe for concurrent use.Click to reveal answer
intermediate
Can classes conform to
Sendable automatically? Why or why not?No, classes do not automatically conform because they have reference semantics and can cause data races. You must manually ensure thread safety and mark them as
Sendable if safe.Click to reveal answer
beginner
What keyword do you use to declare a type as conforming to
Sendable?You use the
Sendable protocol in the type declaration, for example: struct MyType: Sendable { ... }.Click to reveal answer
beginner
Why is
Sendable important in Swift concurrency?Sendable helps the compiler ensure that data passed between concurrent tasks is safe, preventing bugs caused by simultaneous access to mutable state.Click to reveal answer
What does the
Sendable protocol guarantee in Swift?✗ Incorrect
Sendable ensures a type is safe to use across threads, not necessarily immutable or restricted to the main thread.
Which of these types automatically conforms to
Sendable in Swift?✗ Incorrect
Structs with only Sendable properties automatically conform. Classes and enums with reference types do not.
If a class has mutable state, can it conform to
Sendable safely without extra work?✗ Incorrect
Mutable state in classes requires manual thread safety measures before conforming to Sendable.
What happens if you try to pass a non-
Sendable type between concurrent tasks?✗ Incorrect
Swift's compiler checks and warns or errors if non-Sendable types are passed between concurrent contexts.
Which keyword is used to declare a type conforms to
Sendable?✗ Incorrect
The protocol name Sendable is used exactly as is in the type declaration.
Explain what the
Sendable protocol is and why it matters for thread safety in Swift.Think about how Swift prevents data races when sharing data between threads.
You got /4 concepts.
Describe how you would make a custom struct conform to
Sendable safely.Consider what properties your struct has and their thread safety.
You got /4 concepts.