Skip to content

Instantly share code, notes, and snippets.

Created Aug 22, 2021
What would you like to do?
class StringPreference(
private val preferences: SharedPreferences,
private val name: String,
private val defaultValue: String
) : ReadWriteProperty<Any, String?> {
override fun getValue(thisRef: Any, property: KProperty<*>) =
preferences.getString(name, defaultValue) ?: defaultValue
override fun setValue(thisRef: Any, property: KProperty<*>, value: String?) {
preferences.edit {
putString(name, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment