Skip to main content
The Swift SDK gives you full TypeScript-equivalent functionality on Apple platforms (and Linux for server-side Swift). Auth, entity CRUD, optimistic mutations, real-time sync with offline replay, multiplayer shards, Loro CRDTs, and SwiftUI hooks are all native, with no JavaScript bridge.

Modules

Platforms

Install

In Package.swift:
Per target:
Linux: apt-get install libsqlite3-dev for the SQLite-backed offline replica.

Quickstart

SwiftUI

Auth

Entity CRUD

After codegen, the typed wrappers replace the stringly-typed APIs:

Streaming functions

Sync engine

Transports

All three support full-jitter exponential backoff for reconnects.

Pagination

Files

Multiplayer shards

When the server moves the player to another shard (ctx.shards.transfer), the client reconnects there with the ticket the server sent, and shard.shardId changes. transfers() reports each move. When a deploy moves the shard itself to another machine, the client reconnects the same way, shardId stays, and transfers() reports nothing. Set ticketProvider to get a ticket per connection attempt, for the shard it connects to:

Loro CRDTs

For collaborative text/lists/maps/trees, the SDK bridges to loro-swift (the official Swift binding for Loro):
The CRDT logic isn’t reimplemented in Swift. loro-swift wraps the same Rust core as the JS loro-crdt package, so convergence is identical across platforms by construction.

Codegen

Generate typed structs from your manifest:
Produces:
  • struct Todo: Codable, Identifiable, Equatable, Hashable { ... } per entity
  • struct NewTodo: Encodable { ... } for create payloads (id-less variant)
  • struct CreateTodoInput: Encodable { ... } per action input
  • A PylonClient extension with typed listTodos, createTodo, deleteTodo, etc.
  • enum PylonEntities { static let Todo = "Todo"; static let all: [String] = [...] }
Run on every manifest change. Add to your build script.

Persistence

SQLitePersistence mirrors the IndexedDB schema used by the web client:
  • rows(entity, row_id, data) — entity rows
  • cursors(key, last_seq) — sync cursor
  • mutations(id, payload) — offline write queue
WAL mode for concurrent reads while writes happen. All access serialized through a DispatchQueue so async callers don’t hold a sync lock across await.

Background sessions

For long-running uploads / downloads, use a background URLSessionConfiguration:
Use for large file uploads that should continue even when the app is backgrounded.

Storage adapters

Bearer tokens persist via PylonStorage. Default is UserDefaults on Apple platforms, in-memory on Linux. For Keychain-backed token storage:

Differences from the React/JS clients

  • Actor isolation: PylonClient and SyncEngine are actors, so calls into them require await
  • Codable everywhere: entities decode into your Swift structs at the boundary; no JSON-as-Any values
  • Background sessions: Apple’s URLSession.background works
  • No bundler: Swift Package Manager handles versioning, no webpack/esbuild
  • Linux-compatible: server-side Swift apps can use the same SDK

Tests

The package includes 43+ tests covering HTTP, sync engine, mutation queue, SQLite persistence, SSE parser, infinite query, streaming, and Loro frame decoding.

Sample app

examples/swift-todo — minimal SwiftUI iOS app consuming the examples/todo-app manifest. Sign-in, optimistic insert/delete, live updates over WebSocket.

Where to next