Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserDefaults Migration #7

Open
Mazyod opened this issue Oct 15, 2016 · 1 comment
Open

UserDefaults Migration #7

Mazyod opened this issue Oct 15, 2016 · 1 comment

Comments

@Mazyod
Copy link
Member

Mazyod commented Oct 15, 2016

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
Copy link
Member Author

Mazyod commented Oct 15, 2016

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

@Mazyod Mazyod closed this as completed Oct 15, 2016
@Mazyod Mazyod reopened this Mar 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant