home / skills / willsigmon / sigstack / userdefaults-migrator
This skill helps migrate UserDefaults to SwiftData by locating usage, creating entities, updating to PreferencesStore, and archiving keys for a single source
npx playbooks add skill willsigmon/sigstack --skill userdefaults-migratorReview the files below or copy the command above to add this skill to your agents.
---
name: UserDefaults Migrator
description: Find UserDefaults.standard usage in Leavn, migrate to PreferencesStore/SwiftData, create entities, ensure single source of truth
allowed-tools: Read, Write, Edit, Grep
---
# UserDefaults Migrator
Migrate UserDefaults to SwiftData:
1. **Find usage**: `grep -r "UserDefaults.standard"`
2. **Categorize**:
- Keep: Tests, debug flags, widgets
- Migrate: User preferences, stats, settings
3. **Create entity if needed**
4. **Update code to use PreferencesStore**
5. **Write migration logic**
6. **Archive old keys**
Use when: UserDefaults cleanup, preference migration, SwiftData entities
This skill scans a Swift codebase for UserDefaults.standard usage and migrates selected keys to a SwiftData-backed PreferencesStore with a single source of truth. It automates classification, entity creation, migration logic, and archiving of legacy keys to preserve data and avoid duplication. The goal is a predictable, testable preferences layer and fewer scattered defaults across the app.
The tool greps the repository for UserDefaults.standard occurrences and categorizes each usage into keep-or-migrate buckets (tests, debug flags, widgets vs. user preferences, settings, stats). For migratable items it scaffolds SwiftData entities and a PreferencesStore wrapper, inserts migration code to copy legacy values, and replaces usages with the new API. It also writes archival logic for old keys to avoid accidental reuse.
Will this remove keys automatically?
No — it migrates values and archives old keys by renaming or flagging them so you can restore if needed.
Can I migrate only a subset of keys?
Yes — the tool categorizes usages and you choose which groups to migrate; keep categories like tests and widgets out of migration.
Is migration idempotent?
Migration logic is designed to be idempotent: copied values are only moved once and archived keys prevent re-migration.