Skip to main content

Installation

Add InsForge to your Swift Package Manager dependencies:

Enable Logging (Optional)

For debugging, you can configure the SDK log level and destination:
Log Levels: Log Destinations:
Use .info or .error in production to avoid exposing sensitive data in logs.

Mental model

The Swift SDK connects to InsForge Realtime over Socket.IO. Subscribe to channel names such as order:123 or chat:room-1, then listen for event names published to those channels. Events are published by database triggers that call realtime.publish(...) or by clients that publish to a channel they have already joined. See Realtime overview for the channel and RLS model.

Quick start

connect()

Establish a realtime connection.

subscribe()

Subscribe to a channel and receive messages published to it.
If RLS is enabled on realtime.channels, subscription is checked against SELECT policies.

publish()

Publish an event to a channel.
The client must subscribe to a channel before publishing to that same channel.
If RLS is enabled on realtime.messages, publish is also checked against INSERT policies.

unsubscribe()

Leave a channel.

disconnect()

Close the realtime connection.

Channel API

The channel API groups operations for one channel name.

Broadcast messages

Listen for an event:
Publish through the channel:
Remove a channel object when it is no longer needed:

Presence

Successful subscriptions return the current presence snapshot where supported by the SDK API. Listen for presence updates through the channel or lower-level event APIs exposed by the SDK. Presence is ephemeral online state. It is not stored in Postgres.