Complete the code to declare a struct as conforming to the Sendable protocol.
struct DataModel: [1] {
var value: Int
}To mark a struct as safe to use across threads, it must conform to the Sendable protocol.
Complete the code to mark a class as conforming to Sendable.
final class Counter: [1] { var count = 0 }
Marking a class as Sendable indicates it is safe to use across threads.
Fix the error by completing the code to make the struct Sendable when it contains a non-Sendable property.
struct Wrapper: Sendable {
var data: [1]
}Only types that conform to Sendable can be used safely. Int is Sendable, but UnsafeMutablePointer and DispatchQueue are not.
Fill both blanks to create a Sendable struct with a computed property.
struct Point: [1] { var x: Int var y: Int var description: [2] { "(\(x), \(y))" } }
The struct conforms to Sendable and the computed property returns a String.
Fill all three blanks to create a Sendable struct with a closure property marked as @Sendable.
struct Task: [1] { var id: Int var action: [2] () -> Void init(id: Int, action: [3] () -> Void) { self.id = id self.action = action } }
The struct conforms to Sendable. The closure property and initializer parameter are marked @Sendable and have type () -> Void to ensure thread safety.