Skip to content

Instantly share code, notes, and snippets.

@agustarc
Created December 27, 2021 11:13
Show Gist options
  • Save agustarc/44d27dc54598fc587b10495bace97fa8 to your computer and use it in GitHub Desktop.
Save agustarc/44d27dc54598fc587b10495bace97fa8 to your computer and use it in GitHub Desktop.
companion object {
private const val PREF_NAME = "example_pref"
private val EXAMPLE_DATA1 = stringPreferencesKey("exampleData1")
private val EXAMPLE_DATA2 = booleanPreferencesKey("exampleData2")
private val EXAMPLE_DATA3 = intPreferencesKey("exampleData3")
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
name = PREF_NAME,
produceMigrations = { context ->
listOf(SharedPreferencesMigration(context, PREF_NAME, setOf(EXAMPLE_DATA1.name, EXAMPLE_DATA3.name)))
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment