Storez icon indicating copy to clipboard operation
Storez copied to clipboard

UserDefaults Migration

Open Mazyod opened this issue 9 years ago • 1 comments

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)
})

Mazyod avatar Oct 15 '16 10:10 Mazyod

Swift generics isn't helping at all at this point, maybe we can revisit this once its improved.

Mazyod avatar Oct 15 '16 12:10 Mazyod