An experimental DistributedActorSystem for Swift 6 that uses XPC as a transport layer.
Works on macOS only (because XPC support on iOS is extremely limited).
Designed for macOS 15, but might work on earlier versions.
⚠️ Lacks XPC security mechanisms⚠️ Barely tested- Actor ID assignment needs improvement
Two example projects are included (for an XPC Service and a Launch Daemon). They are the best starting point to see how this system works.
To run the examples, you need to set your development team by duplicating the file Config.xcconfig.template
, renaming it to Config.xcconfig
and update it with your Development Team Identifier:
DEVELOPMENT_TEAM = <YOUR_DEVELOPMENT_TEAM_IDENTIFIER>
Short code sample:
import XPCDistributedActorSystem
import Calculator
// Set up the system
let xpc = XPCDistributedActorSystem(mode: .connectingToXPCService(serviceName: yourServiceName))
let calculator = try Calculator.resolve(id: .init(1), using: xpc)
// Run function in the XPC service and print the result
let result = try await calculator.add(number1, number2)
print(result)
import XPCDistributedActorSystem
import Calculator
let system = XPCDistributedActorSystem(mode: .receivingConnections)
let calculator = Calculator(actorSystem: system)
let listener = try XPCServiceListener(actorSystem: system)
listener.run()
All the types referenced by the distributed actor need to be available to both XPC endpoints – and they have to be absolutely identical, because demangling for the distributed actor will fail otherwise.
The easiest way is to just put the distributed actor and all types required for its functionality inside a Library, and add that Library to both targets.
- Implement a way to share status with
@Observable
Feel free to fork (see license) or contribute.