mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2025-12-11 20:15:30 +01:00
…
Spacedrive Swift Client
A type-safe Swift client for interacting with the Spacedrive daemon.
Features
- Type Safety: Full compile-time type checking with generated Swift types
- Automatic Generation: Types are automatically generated from Rust definitions
- Simple API: Three core methods:
executeQuery,executeAction, andsubscribe - Modern Swift: Uses async/await and AsyncStream for clean asynchronous code
Installation
Swift Package Manager
Add this to your Package.swift:
dependencies: [
.package(path: "path/to/spacedrive/packages/swift-client")
]
Usage
import SpacedriveClient
// Initialize the client
let client = SpacedriveClient(socketPath: "/path/to/daemon.sock")
// Execute a query
let status = try await client.executeQuery(
CoreStatusQuery(),
method: "query:core.status",
responseType: CoreStatus.self
)
// Execute an action
let result = try await client.executeAction(
LibraryCreateInput(name: "My Library"),
method: "action:libraries.create.input",
responseType: LibraryCreateOutput.self
)
// Subscribe to events
for await event in client.subscribe(to: ["JobProgress", "JobCompleted"]) {
print("Received event: \(event)")
}
Development
Regenerating Types
After making changes to Rust types in the core:
-
Build the core to generate the schema:
cd core && cargo build -
Regenerate the Swift client:
cd packages/swift-client ./generate_client.sh
Requirements
- Swift 5.9+
- macOS 13+ or iOS 16+
- quicktype (for type generation):
npm install -g quicktype
Architecture
The client uses a two-layer architecture:
- Generated Types Layer:
types.swiftcontains all the generated types from quicktype - Client API Layer:
SpacedriveClient.swiftprovides the clean, user-facing API
This separation ensures that the generated types don't pollute the main API and can be regenerated without affecting user code.