Skip to content

UserDefaults Migration #7

@Mazyod

Description

@Mazyod

Add user defaults migration helper, which takes a list of of MigrationInfo. MigrationInfo is a struct that contains a KeyType to be migrated to, String which is the old key, and a processing block, that takes the old value and processes it to to return a new suitable value for KeyType.

This is the actual use case that I have. I have simplified it so it makes more sense:

old value: "CityId" -> "kw-city-asimah"
new key: "general-settings:city" -> ""

so, we can do this:

let migrationInfo = MigrationInfo(
  keyType = Key<GeneralSettings, City>(id: "city", defaultValue: City.asimah),
  oldKey = "CityId",
  processor = { oldValue in
    // process from a string to a City type
    return mydb.getCity(oldValue)
})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions