安装
Add InsForge to your Swift Package Manager dependencies:Enable Logging (Optional)
For debugging, you can configure the SDK log level and destination:| Level | Description |
|---|---|
.trace | Most verbose, includes all internal details |
.debug | Detailed information for debugging |
.info | General operational information (default) |
.warning | Warnings that don’t prevent operation |
.error | Errors that affect functionality |
.critical | Critical failures |
| Destination | Description |
|---|---|
.console | Standard output (print) |
.osLog | Apple’s unified logging system (recommended for iOS/macOS) |
.none | Disable logging |
.custom | Provide your own LogHandler factory |
Use
.info or .error in production to avoid exposing sensitive data in logs.思维模型
Swift SDK 通过 Socket.IO 连接到 InsForge 实时。订阅频道名称,如order:123 或 chat:room-1,然后监听发布到这些频道的事件名称。
事件由数据库触发器发布,这些触发器调用 realtime.publish(...) 或由已加入频道的客户端发布。有关频道和 RLS 模型的详细信息,请参阅实时概览。
快速入门
connect()
建立实时连接。subscribe()
订阅一个频道并接收发布到该频道的消息。realtime.channels 上启用了 RLS,订阅会根据 SELECT 策略进行检查。
publish()
发布一个事件到频道。客户端必须订阅频道才能发布到该频道。
realtime.messages 上启用了 RLS,发布也会根据 INSERT 策略进行检查。