What problem does it solve?
Realm's thread-confinement model conflicts with Swift Concurrency, leading to crashes and hard-to-debug issues. This skill provides safe patterns (Actor-based fresh Realm, @MainActor usage, and proper autorelease pools) to write robust Realm code for iOS apps.
Core Features & Use Cases
- Actor + Fresh Realm: Create a new Realm per operation inside an actor to prevent cross-thread access.
- @MainActor Pattern: For UIKit apps with small datasets, perform reads/writes on the main thread using a single Realm instance.
- Background Thread with Autorelease Pool: Safely run Realm work on background threads by wrapping in an autorelease pool.
- DTO Pattern for Codable APIs: Use DTOs to keep Realm models separate from network or persistence APIs.
Quick Start
Use the realm-persistence skill to implement a thread-safe Realm usage pattern by using a fresh Realm per operation within an Actor.