SeuraaEdge
v1
Docs/SDKs
SDKs

Connect Apple applications with the Swift client.

Swift Client SDK

The Swift client connects iOS, macOS, tvOS, and watchOS applications to Edge.

Installation

Add the Swift package URL and version supplied with your Edge account, then add SeuraaEdge to the application target.

Client

swift
import SeuraaEdge

let edge = Client(
    options: ClientOptions(
        appKey: "app-key",
        auth: URL(string: "https://api.example.com/seuraa/token")!
    )
)

The auth URL receives the app key and channel name and returns a short-lived channel token.

Use tokenProvider instead when the application needs custom authentication headers or token-fetching behavior.

Subscribe

swift
struct Notification: Codable, Sendable {
    let title: String
}

let channel = edge.channel("private:user-123")

let subscription = channel.subscribe(
    "notification.created",
    as: Notification.self
) { event in
    print(event.data.title)
}

Calling subscription.cancel() removes only that event handler. Call channel.unsubscribe() to leave the channel.

Publish

swift
struct Typing: Codable, Sendable {
    let documentID: String
}

let result = await channel.publish(
    "typing.started",
    data: Typing(documentID: "document-123")
)

Publishing is asynchronous because the SDK may refresh the channel token.

Connection Status

swift
for await state in edge.status {
    print(state.status)
}

The client reconnects automatically and restores active channel subscriptions. On plans with persisted replay, it also resumes channels using their latest event cursors.

Presence And Errors

swift
let rawEvents = channel.onRawEvent { event in
    switch event {
    case .presenceUpdated(let update):
        print(update.presence?.members ?? [])
    case .serverError(let error):
        print(error.code)
    default:
        break
    }
}

Call edge.close() when the client is no longer needed.