Browse Questions
  • An actor is a reference type that protects its mutable state from concurrent access.
  • Sendable is a protocol that marks a type as safe to share across concurrency domains (actors, tasks).
  • TaskGroup lets you run multiple async tasks in parallel and collect all their results.
  • TCA is an open-source architecture library by Point-Free.

Answer: Sendable is a protocol that marks a type as safe to share across concurrency domains (actors, tasks). The compiler enforces this to prevent data races at compile time.

Code Example:

// Structs with Sendable properties are automatically Sendable
struct UserProfile: Sendable {
    let id: Int
    let name: String
}

// Classes need to be carefully marked — only if truly thread-safe
final class ImmutableConfig: Sendable {
    let apiKey: String
    init(apiKey: String) { self.apiKey = apiKey }
}

// Actor — implicitly Sendable
actor DataCache {
    var items: [String: Data] = [:]
}

// ⚠️ This causes a compiler error — non-Sendable type crossing actor boundary
class NonSendableData { var value = 0 }

actor MyActor {
    func process(_ data: NonSendableData) { } // ❌ compiler warning
}