Realm.Results

Instances of this class are typically live collections returned by objects() that will update as new objects are either added to or deleted from the Realm that match the underlying query. Results returned by snapshot(), however, are will not live update.

length
readonly

The number of objects in the results.

Type:
number
filtered(query, arg)Realm.Results

Returns new results that are filtered by the provided query.

let merlots = wines.filtered('varietal == "Merlot" && vintage <= $0', maxYear);
Parameters:
  • query
    • Type: string
    • Query used to filter results.

  • arg optional repeatable
    • Type: any
    • Each subsequent argument is used by the placeholders (e.g. $0, $1, $2, …) in the query.

Throws:
  • Error
    • If the query or any other argument passed into this method is invalid.

Returns: Realm.Results filtered according to the provided query.
snapshot()Realm.Results

Create a frozen snapshot of the results. This means changes to the list will not be reflected in the results returned by this method. However, deleted objects will become null at their respective indices.

Returns: Realm.Results which will not live update.
sorted(descriptor, reverse)Realm.Results

Returns new results that are sorted by the provided property (or properties) of each object.

Parameters:
  • descriptor
    • Type: string or [SortDescriptor, ...]
    • The property name(s) to sort results by.

  • reverse optional
    • Type: boolean
    • Default: false
    • May only be provided if descriptor is a string.

Throws:
  • Error
    • If a specified property does not exist.

Returns: Realm.Results sorted according to the arguments passed in
SortDescriptor

The sort descriptors may either just be a string representing the property name, or an array with two items: [propertyName, reverse]

Type:
string or Array