# Ha IOS Persistence

> Ha IOS Persistence is an Agent Skill for development published in the home-assistant/iOS repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

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.

- Skill name: `ha-ios-persistence`
- Category: [Development](https://www.openparable.com/skill/development/1)
- Source: https://github.com/home-assistant/iOS/blob/HEAD/.agents/skills/ha-ios-persistence/SKILL.md
- Repository: home-assistant/iOS (2,262 GitHub stars when collected)

## SKILL.md

# 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.

---

Source: https://www.openparable.com/skill/development/ha-ios-persistence (OpenParable). Cite the canonical URL above.
