Realm.Dictionary

Instances of this class will be returned when accessing object properties whose type is "Dictionary" (see ObjectSchemaProperty).

Dictionaries behave mostly like a JavaScript object i.e., as a key/value pair where the key is a string.

addListener(callback)

Add a listener callback.

Parameters:
  • callback
    • Type: callback(dictionary, changeset)
    • Function to be called when a change event occurs. Each callback will only be called once per event, regardless of the number of times it was added. The callback has two arguments:

      • dictionary: the dictionary instance that changed
      • changeset: an object of array of keys changed (deletions, insertions, and modifications)
Throws:
  • Error
    • If callback is not a function.

remove(key)

Remove a key from the dictionary. It is also possible to use the keyword delete.

Parameters:
  • key
    • Type: string
    • The key to be removed.

Throws:
  • Error
    • If not inside a write transaction

removeAllListeners()

Remove all event listeners.

removeListener(callback)

Remove the listener callback.

Parameters:
  • callback
    • Type: callback(Realm.Dictionary, Realm.Dictionary.Changeset)
    • Function that was previously added as a listener through the addListener method.

Throws:
  • Error
    • If callback is not a function.

set(key, value)

Add a key with a value or update value if key exists.

Parameters:
  • key
    • Type: string
    • The key to be added or set

  • value
    • The value

Throws:
  • Error
    • If not inside a write transaction or if value violates type constraints