RealmList

RealmList is used to model one-to-many relationships in a RealmObject or EmbeddedRealmObject.

A RealmList has two modes: managed and unmanaged. In managed mode all objects are persisted inside a Realm whereas in unmanaged mode it works as a normal MutableList.

Only Realm can create managed RealmLists. Managed RealmLists will automatically update their content whenever the underlying Realm is updated. Said content can only be accessed using the getter of a RealmObject or EmbeddedRealmObject.

Unmanaged RealmLists can be created by the user and can contain both managed and unmanaged RealmObjects or EmbeddedRealmObjects. This is useful when dealing with JSON deserializers like Gson or other frameworks that inject values into a class. Unmanaged elements in a list can be added to a Realm using the MutableRealm.copyToRealm method.

Deleting a list through MutableRealm.delete or DynamicMutableRealm.delete will delete any referenced objects from the realm and clear the list.

Parameters

E

the type of elements contained in the RealmList.

Properties

Link copied to clipboard
abstract override val size: Int

Functions

Link copied to clipboard
abstract override fun add(element: E): Boolean
abstract fun add(index: Int, element: E)
Link copied to clipboard
abstract override fun addAll(elements: Collection<E>): Boolean
abstract fun addAll(index: Int, elements: Collection<E>): Boolean
Link copied to clipboard
abstract fun asFlow(keyPaths: List<String>? = null): Flow<ListChange<E>>

Observes changes to the RealmList. The Flow will emit InitialList once subscribed, and then UpdatedList on every change to the list. The flow will continue running indefinitely until canceled or until the parent object is deleted.

Link copied to clipboard
abstract override fun clear()
Link copied to clipboard
abstract operator override fun contains(element: E): Boolean
Link copied to clipboard
abstract override fun containsAll(elements: Collection<E>): Boolean
Link copied to clipboard
inline fun <T : TypedRealmObject> RealmList<T>.copyFromRealm(depth: UInt = UInt.MAX_VALUE): List<T>

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

Link copied to clipboard
abstract operator fun get(index: Int): E
Link copied to clipboard
abstract fun indexOf(element: E): Int
Link copied to clipboard
abstract override fun isEmpty(): Boolean
Link copied to clipboard
abstract operator override fun iterator(): Iterator<E>
Link copied to clipboard
abstract fun lastIndexOf(element: E): Int
Link copied to clipboard
abstract override fun listIterator(): MutableListIterator<E>
abstract override fun listIterator(index: Int): MutableListIterator<E>
Link copied to clipboard
fun <T : BaseRealmObject> RealmList<T>.query(filter: String = TRUE_PREDICATE, vararg arguments: Any?): RealmQuery<T>

Query the objects in a list by filter and arguments.

Link copied to clipboard
abstract override fun remove(element: E): Boolean
Link copied to clipboard
abstract override fun removeAll(elements: Collection<E>): Boolean
Link copied to clipboard
abstract fun removeAt(index: Int): E
Link copied to clipboard
abstract override fun retainAll(elements: Collection<E>): Boolean
Link copied to clipboard
abstract operator override fun set(index: Int, element: E): E

Replaces the element at the specified position in this list with the specified element.

Link copied to clipboard
abstract override fun subList(fromIndex: Int, toIndex: Int): MutableList<E>
Link copied to clipboard

Instantiates an unmanaged RealmDictionary containing all the elements of this iterable of Pairs of Strings and Ts.

Link copied to clipboard

Instantiates an unmanaged RealmList containing all the elements of this iterable.

Link copied to clipboard

Instantiates an unmanaged RealmSet containing all the elements of this iterable.