asProperty

fun <T> Preferences.asProperty(serializer: KSerializer<T>, tag: String? = null): ReadWriteProperty<Any?, T>

Encodes changes to the delegated property into the SharedPreferences and decodes the current value from them.

var setting by preferences.asProperty(Boolean.serializer())

Parameters

serializer

which encodes and decodes the value

tag

optional tag which is used as SharedPreferences key - default to property name


fun <T> Preferences.asProperty(serializer: KSerializer<T>, tag: String? = null, default: T): ReadWriteProperty<Any?, T>

Encodes changes to the delegated property into the SharedPreferences and decodes the current value from them.

var setting by preferences.asProperty(Boolean.serializer(), tag = "aSetting", default = false)

Parameters

serializer

which encodes and decodes the value

tag

optional tag which is used as SharedPreferences key - default to property name

default

optional default value for not initialized preferences


inline fun <T> Preferences.asProperty(tag: String? = null): ReadWriteProperty<Any?, T>

Encodes changes to the delegated property into the SharedPreferences and decodes the current value from them.

var setting: Boolean by preferences.asProperty()

Parameters

tag

optional tag which is used as SharedPreferences key - default to property name


inline fun <T> Preferences.asProperty(tag: String? = null, default: T): ReadWriteProperty<Any?, T>

Encodes changes to the delegated property into the SharedPreferences and decodes the current value from them.

var setting: Boolean by preferences.asProperty(tag = "aSetting", default = false)

Parameters

tag

optional tag which is used as SharedPreferences key - default to property name

default

optional default value for not initialized preferences