SuperAPI AI Directory

swiftdata migration writer

Data & analytics

View repository

Updated 10-16 04:26

About this skill

SwiftData Migration Writer

Create migration from UserDefaults to SwiftData:

  1. Map keys to entity fields

  2. Write migration method:

    func migrateXIfNeeded() async throws {
        guard !hasMigrated("X") else { return }
        // Read UserDefaults
        // Create/update entity
        // Archive old keys
        // Mark migrated
    }
    
  3. Add to PreferencesStore extension

  4. Call on first load

  5. Test data preservation

Use when: Creating SwiftData entities, migrating preferences, data persistence