home / skills / derklinke / codex-config / ios-supabase-realtime-ios

ios-supabase-realtime-ios skill

/skills/ios-supabase-realtime-ios

This skill helps iOS developers implement and optimize Supabase Realtime with Postgres, Broadcast, or Presence, ensuring correct lifecycle and best practices.

npx playbooks add skill derklinke/codex-config --skill ios-supabase-realtime-ios

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
1.2 KB
---
name: supabase-realtime-ios
description: Use when implementing or reviewing Supabase Realtime in iOS/Swift apps (supabase-swift). Covers Postgres Changes, Broadcast, Presence, channel lifecycle, and best practices.
---

# Supabase Realtime (iOS / Swift)

## When to use

- The request mentions Supabase Realtime, Postgres changes, broadcast, presence, or realtime channels on iOS/Swift.
- The task needs Swift SDK patterns, channel lifecycle, or realtime best practices.

## Workflow (concise)

1. Clarify which Realtime mode is needed: Postgres Changes vs Broadcast vs Presence.
2. Use Context7 `/supabase/supabase-swift` to confirm current Swift API shapes (Realtime V2 vs v1).
3. Use Supabase docs for product behavior, limits, replication, and security details.
4. Choose the right mode:
   - Postgres Changes for authoritative DB events.
   - Broadcast for low-latency, ephemeral client-to-client messages.
   - Presence for shared state and online user lists.
5. On iOS, wire lifecycle: subscribe on view appear/foreground, clean up on disappear/background.

## References

- `references/realtime-overview.md` for concepts, tradeoffs, and server-side setup.
- `references/swift-realtime-patterns.md` for Swift/iOS usage patterns.

Overview

This skill helps implement and review Supabase Realtime features in iOS/Swift apps using the supabase-swift SDK. It focuses on choosing the correct realtime mode (Postgres Changes, Broadcast, Presence), wiring channel lifecycle to iOS app states, and applying production-safe patterns. The guidance is practical and targeted at engineers building realtime behaviors on Apple platforms.

How this skill works

It inspects your use of Supabase Realtime concepts and maps them to Swift SDK patterns, emphasizing channel subscription, message handling, and cleanup. It checks whether you chose Postgres Changes, Broadcast, or Presence appropriately and recommends API shapes and lifecycle hooks for view controllers and app background/foreground events. It also flags common pitfalls like missing cleanup, excessive subscriptions, or insecure channel usage.

When to use it

  • You are building server-authoritative event flows or sync based on Postgres changes.
  • You need low-latency client-to-client messaging where messages don’t persist (Broadcast).
  • You want shared presence/state like online user lists or cursors (Presence).
  • You are reviewing an iOS codebase for realtime correctness and lifecycle handling.
  • You need guidance mapping Supabase realtime concepts to Swift idioms and app lifecycle events.

Best practices

  • Select Postgres Changes for authoritative DB events; avoid using Broadcast as a source of truth.
  • Subscribe in viewDidAppear / sceneWillEnterForeground and unsubscribe in viewDidDisappear / sceneDidEnterBackground to prevent orphaned channels.
  • Use a single channel per logical scope and multiplex messages with topics to limit socket count.
  • Validate and enforce RLS and channel authorization server-side; do not trust client-sent topics or payloads.
  • Debounce UI updates from high-frequency events and batch writes to reduce churn and cost.

Example use cases

  • Reflect backend inserts/updates in the UI by subscribing to Postgres Changes for a table and applying diffs to local models.
  • Implement a chat room using Broadcast for ephemeral messages and Presence to show active participants.
  • Build collaborative cursors or editing indicators using Presence to sync small state objects across clients.
  • Audit an iOS app to replace multiple redundant sockets with a single channel and proper lifecycle hooks.

FAQ

When should I use Broadcast vs Postgres Changes?

Use Postgres Changes when events must reflect durable DB state. Use Broadcast for ephemeral client messages where durability and ordering are not required.

How do I avoid memory leaks with realtime channels on iOS?

Tie subscriptions to view/controller lifecycle: subscribe on appear/foreground and explicitly leave channels and remove listeners on disappear/background. Prefer a centralized connection manager to oversee cleanup.