Actors in Swift
From the Swift cheat sheet · Concurrency · verified Jul 2026
Actors
Thread-safe reference types
swift
// Actor definition
actor BankAccount {
private var balance: Double = 0
func deposit(amount: Double) {
balance += amount
}
func withdraw(amount: Double) -> Bool {
guard balance >= amount else {
return false
}
balance -= amount
return true
}
func getBalance() -> Double {
return balance
}
}
// Using actors
let account = BankAccount()
Task {
await account.deposit(amount: 100)
let success = await account.withdraw(amount: 50)
let balance = await account.getBalance()
print("Balance: \(balance)")
}💡 Actors provide thread-safe access to mutable state
⚡ All actor methods are implicitly async
📌 Sendable ensures types are safe to share across threads
🟢 Use actors to prevent data races