Swift: Realtime
Join channels, send and receive messages, follow connection status and catch up after a reconnect with the Swift SDK.
Join channels, send and receive messages, follow connection status and catch up after a reconnect. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.
#Types and members
RealtimeStatus
The same states as the TypeScript and Dart clients: connecting (first attempt), live, reconnecting (dropped, retrying with backoff) and closed (closed by you, or refused: signed out, not allowed, misconfigured).
public enum RealtimeStatus: Sendable, EquatableValues: connecting, live, reconnecting, closed.
RealtimeStatus.open
A property.
public static var open: RealtimeStatusSovariaRealtime
Realtime channels. publish and presence work over HTTP; channel(_:) opens a WebSocket that delivers messages and reconnects with backoff. The token never goes in the URL — a one-time ticket does.
public final class SovariaRealtime: @unchecked SendableSovariaRealtime.channel
Open a channel and receive its messages.
public func channel(_ name: String, onMessage: @escaping @Sendable ([String: Any]) -> Void,
onStatus: (@Sendable (RealtimeStatus) -> Void)? = nil,
catchUp: Bool = true,
onGap: (@Sendable (RealtimeGap) -> Void)? = nil) -> RealtimeChannelKeep the returned object; call close() when done.
catchUp: after a reconnect, deliver the messages published while the socket was down (from the channel's replay history) — in order, once each — before new ones. onGap: messages that were missed and can't be recovered (older than the retained history, or the history couldn't be read); reload state when it fires.
SovariaRealtime.publish
Publish to a channel over HTTP (no socket needed).
public func publish(_ channel: String, _ payload: [String: Any]) async throwsSovariaRealtime.replay
Messages after after (by stream_seq), oldest first: ["events": [...]].
public func replay(_ channel: String, after: Int = 0, limit: Int = 200) async throws -> Any?SovariaRealtime.presence
Who is in a channel right now.
public func presence(_ channel: String) async throws -> Any?SovariaRealtime.closeAll
public func closeAll()RealtimeChannel
One open realtime channel. Reconnects on drop with capped backoff until close().
A WebSocket ping goes out every 30 s; a socket that answers none within 10 s is treated as dead and reopened, so a connection cut by NAT or radio sleep no longer sits "open" for minutes while messages are lost (SDK2-M13).
public final class RealtimeChannel: NSObject, @unchecked SendableRealtimeChannel.name
A property.
public let name: StringRealtimeChannel.send
Publish a message to everyone on the channel.
public func send(_ payload: [String: Any]) async throwsRealtimeChannel.close
public func close()RealtimeGap
Messages fromSeq...toSeq (by stream_seq) were missed and can't be recovered; toSeq is nil when the history couldn't be read. reason: not_retained or replay_failed. Reload state from the source of truth.
public struct RealtimeGap: Sendable, EquatableRealtimeGap.fromSeq
A property.
public let fromSeq: IntRealtimeGap.toSeq
A property.
public let toSeq: Int?RealtimeGap.reason
A property.
public let reason: String