All property types except for List and RealmOptionalmust be declared as @objc dynamic var. List and
RealmOptional properties must be declared as non-dynamic let properties. Swift lazy properties are not allowed.

Note that none of the restrictions listed above apply to properties that are configured to be ignored by Realm.

Querying

You can retrieve all objects of a given type from a Realm by calling the objects(_:) instance method.

Declaration

The value argument is used to populate the object. It can be a key-value coding compliant object, an array or
dictionary returned from the methods in NSJSONSerialization, or an Array containing one element for each
managed property. An exception will be thrown if any required properties are not present and those properties were
not defined with default values.

When passing in an Array as the value argument, all properties must be present, valid and in the same order as
the properties defined in the model.

Call add(_:) on a Realm instance to add an unmanaged object into that Realm.

Declaration

Declaration

Override this method to specify the name of a property to be used as the primary key.

Only properties of types String and Int can be designated as the primary key. Primary key properties enforce
uniqueness for each value whenever the property is set, which incurs minor overhead. Indexes are created
automatically for primary key properties.

Declaration

Swift

@objcopenclassfuncprimaryKey()->String?

Return Value

The name of the property designated as the primary key, or nil if the model has no primary key.

Return Value

The block will be asynchronously called after each write transaction which
deletes the object or modifies any of the managed properties of the object,
including self-assignments that set a property to its existing value.

For write transactions performed on different threads or in different
processes, the block will be called when the managing Realm is
(auto)refreshed to a version including the changes, while for local write
transactions it will be called at some point in the future after the write
transaction is committed.

Notifications are delivered via the standard run loop, and so can’t be
delivered while the run loop is blocked by other activity. When
notifications can’t be delivered instantly, multiple notifications may be
coalesced into a single notification.

Unlike with List and Results, there is no initial callback made after
you add a new notification block.

Only objects which are managed by a Realm can be observed in this way. You
must retain the returned token for as long as you want updates to be sent
to the block. To stop receiving updates, call stop() on the token.

It is safe to capture a strong reference to the observed object within the
callback block. There is no retain cycle due to that the callback is
retained by the returned token and not by the object itself.

Warning

This method cannot be called during a write transaction, or when
the containing Realm is read-only.