Ha IOS Persistence

Data persistence across GRDB, Realm, and UserDefaults. Use when adding or migrating a persistent model, choosing a storage layer, implementing DatabaseTableProtocol, or reading/writing config for Watch, CarPlay, widgets, or the entity registry.

home-assistant ac3e0e8 999 B Updated

File contents

Data Persistence

The project uses two database layers:

  • GRDB (GRDB.swift): newer layer, accessed via Current.database(). Used for Watch config, CarPlay config, widget config, entity registry, panels, etc. When adding a new persistent model, prefer GRDB: implement DatabaseTableProtocol (defines tableName, definedColumns, and createIfNeeded) and register it in DatabaseQueue.tables() in GRDB+Initialization.swift. The protocol's migrateColumns helper auto-handles additive migrations.
  • Realm (RealmSwift): legacy layer, used for older models (actions, zones, sensors, etc.). Access via Current.realm().
  • UserDefaults: simple preferences and watch communication.

home-assistant/ios/tree/main/.agents/skills/ha-ios-persistence commit ac3e0e8fe1

Frequently asked questions

npx skillmds@latest add home-assistant/ha-ios-persistence