MutablePreferences
class MutablePreferences : Preferences
kotlin.Any | ||
↳ | androidx.datastore.preferences.core.Preferences | |
↳ | androidx.datastore.preferences.core.MutablePreferences |
Mutable version of Preferences. Allows for creating Preferences with different key-value pairs.
Summary
Public methods | |
---|---|
Map<Preferences.Key<*>, Any> |
asMap() Retrieve a map of all key preference pairs. |
Unit |
clear() |
operator Boolean |
contains(key: Preferences.Key<T>) Returns true if this Preferences contains the specified key. |
Boolean | |
operator T? |
get(key: Preferences.Key<T>) Get a preference with a key. |
Int |
hashCode() |
operator Unit |
minusAssign(key: Preferences.Key<*>) Removes the preference with the given key from this MutablePreferences. |
operator Unit |
plusAssign(prefs: Preferences) Appends or replaces all pairs from prefs to this MutablePreferences. |
operator Unit |
plusAssign(pair: Preferences.Pair<*>) Appends or replaces all pair to this MutablePreferences. |
Unit |
putAll(vararg pairs: Preferences.Pair<*>) Appends or replaces all pairs to this MutablePreferences. |
T |
remove(key: Preferences.Key<T>) Remove a preferences from this MutablePreferences. |
operator Unit |
set(key: Preferences.Key<T>, value: T) Set a key value pair in MutablePreferences. |
String |
toString() For better debugging. |
Inherited functions | |
---|---|
Public methods
asMap
fun asMap(): Map<Preferences.Key<*>, Any>
Retrieve a map of all key preference pairs. The returned map is unmodifiable, and attempts to mutate it will throw runtime exceptions.
Return | |
---|---|
a map containing all the preferences in this Preferences |
clear
fun clear(): Unit
contains
operator fun <T> contains(key: Preferences.Key<T>): Boolean
Returns true if this Preferences contains the specified key.
Parameters | |
---|---|
key: Preferences.Key<T> | the key to check for |
get
operator fun <T> get(key: Preferences.Key<T>): T?
Get a preference with a key. If the key is not set, returns null.
If T is Set, this returns an unmodifiable set which will throw a runtime exception when mutated. Do not try to mutate the returned set.
Use MutablePreferences.set to change the value of a preference (inside a DataStore.edit block).
Parameters | |
---|---|
T |
the type of the preference |
key: Preferences.Key<T> | the key for the preference |
Exceptions | |
---|---|
ClassCastException |
if there is something stored with the same name as key but it cannot be cast to T |