Skip to content

Instantly share code, notes, and snippets.

@sergei-mikhailovskii-idf
Created December 7, 2023 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergei-mikhailovskii-idf/806a1fa9e3acaac0321dbeb83185d0f4 to your computer and use it in GitHub Desktop.
Save sergei-mikhailovskii-idf/806a1fa9e3acaac0321dbeb83185d0f4 to your computer and use it in GitHub Desktop.
actual fun getNonEncryptedSettings(context: AppContext?): Settings =
NSUserDefaultsSettings(NSUserDefaults.standardUserDefaults)
@OptIn(ExperimentalSettingsImplementation::class)
actual fun getEncryptedSettings(context: AppContext?): Settings =
MigrationSettings(
listOf("key1", "key2"),
getNonEncryptedSettings(context),
KeychainSettings("${NSBundle.mainBundle.bundleIdentifier}.AUTH")
)
@OptIn(ExperimentalSettingsImplementation::class)
private class MigrationSettings(
keysToMigrate: List<String>,
oldSettings: Settings,
val keychainSettings: KeychainSettings
) : Settings by keychainSettings {
init {
keysToMigrate.forEach { key ->
val value = oldSettings.getStringOrNull(key)
value?.let {
putString(key, it)
oldSettings.remove(key)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment