Created
December 7, 2023 21:03
-
-
Save sergei-mikhailovskii-idf/806a1fa9e3acaac0321dbeb83185d0f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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