Junior — Middle
What is the purpose of the Sendable interface in the system?
sobes.tech AI
Answer from AI
The Sendable interface in iOS (Swift Concurrency) is used to mark types that can be safely transferred between different threads or tasks. This is important for preventing data races and ensuring safety when working with concurrency.
Types that conform to Sendable guarantee that their state will not be modified simultaneously from multiple threads without synchronization.
Example:
struct Message: Sendable {
let text: String
}
func sendMessage(_ message: some Sendable) {
// It is safe to pass message between tasks
}