RealmDictionary

A RealmDictionary is a specialization for RealmMaps whose keys are Strings.

Similarly to RealmList or RealmSet, RealmMap can operate in managed and unmanaged modes. In managed mode a RealmDictionary persists all its contents in a Realm instance whereas unmanaged dictionaries are backed by an in-memory LinkedHashMap.

A managed dictionary can only be created by Realm and will automatically update its content whenever its underlying realm is updated. Managed dictionaries can only be accessed using the getter that points to a RealmDictionary property of a managed RealmObject.

Unmanaged dictionaries can be created by calling realmDictionaryOf and may contain both managed and unmanaged RealmObjects. Unmanaged dictionaries can be added to a realm using the MutableRealm.copyToRealm function with an object containing an unmanaged dictionary.

A RealmDictionary may contain any type of Realm primitive nullable and non-nullable values. RealmObjects and EmbeddedRealmObjects are also supported but must be declared nullable.

Parameters

V

the type of the values stored in this map

Properties

Link copied to clipboard
Link copied to clipboard
abstract override val keys: MutableSet<String>
Link copied to clipboard
abstract val size: Int
Link copied to clipboard
abstract override val values: MutableCollection<V>

Functions

Link copied to clipboard
abstract fun asFlow(keyPaths: List<String>? = null): Flow<MapChange<String, V>>

Observes changes to the RealmMap. The Flow will emit InitialMap once subscribed, and then UpdatedMap on every change to the dictionary. The flow will continue running indefinitely until canceled or until the parent object is deleted.

Link copied to clipboard
abstract fun clear()
Link copied to clipboard
abstract fun containsKey(key: String): Boolean
Link copied to clipboard
abstract fun containsValue(value: V): Boolean
Link copied to clipboard
inline fun <T : RealmObject> RealmDictionary<T?>.copyFromRealm(depth: UInt = UInt.MAX_VALUE): Map<String, T?>

Makes an unmanaged in-memory copy of the elements in a managed RealmDictionary. This is a deep copy that will copy all referenced objects.

Link copied to clipboard
abstract operator fun get(key: String): V?
Link copied to clipboard
abstract fun isEmpty(): Boolean
Link copied to clipboard
abstract fun put(key: String, value: V): V?
Link copied to clipboard
abstract fun putAll(from: Map<out String, V>)
Link copied to clipboard
fun <T : BaseRealmObject> RealmDictionary<T?>.query(filter: String = TRUE_PREDICATE, vararg arguments: Any?): RealmQuery<T>

Query the objects in a dictionary by filter and arguments. The query is launched against the output obtained from RealmDictionary.values. This means keys are not taken into consideration.

Link copied to clipboard
abstract fun remove(key: String): V?
Link copied to clipboard

Instantiates an unmanaged RealmDictionary containing all the elements of the receiver dictionary represented by a Map of String to T pairs.