PrefDelegate

class PrefDelegate<T>(prefs: SharedPreferences, key: String, defaultValue: T) : ReadWriteProperty<Any?, T>

A generic ReadWriteProperty delegate that provides concise, type-safe access to SharedPreferences.

Parameters

prefs

The SharedPreferences instance to back the property.

key

The key used to store and retrieve the value.

defaultValue

The default value to return if no value is found.

Throws

if the type is not supported.

Constructors

Link copied to clipboard
constructor(prefs: SharedPreferences, key: String, defaultValue: T)

Functions

Link copied to clipboard
open operator override fun getValue(thisRef: Any?, property: KProperty<*>): T
Link copied to clipboard
open operator override fun setValue(thisRef: Any?, property: KProperty<*>, value: T)