Structures
The following structures are available globally.
-
A
Realm
instance (also referred to asa Realm
) represents a Realm database.Realms can either be stored on disk (see
init(path:)
) or in memory (seeConfiguration
).Realm
instances are cached internally, and constructing equivalentRealm
objects (for example, by using the same path or identifier) produces limited overhead.If you specifically want to ensure a
Realm
instance is destroyed (for example, if you wish to open a Realm, check some property, and then possibly delete the Realm file and re-open it), place the code which uses the Realm within anautoreleasepool {}
and ensure you have no other strong references to it.Warning
Realm
instances are not thread safe and cannot be shared across threads or dispatch queues. You must construct a new instance for each thread in which a Realm will be accessed. For dispatch queues, this means that you must construct a new instance in each block which is dispatched, as a queue is not guaranteed to run all of its blocks on the same thread.Declaration
Swift
public struct Realm
-
LinkingObjects
is an auto-updating container type. It represents zero or more objects that are linked to its owning model object through a property relationship.LinkingObjects
can be queried with the same predicates asList<Element>
andResults<Element>
.LinkingObjects
always reflects the current state of the Realm on the current thread, including during write transactions on the current thread. The one exception to this is when usingfor...in
enumeration, which will always enumerate over the linking objects that were present when the enumeration is begun, even if some of them are deleted or modified to no longer link to the target object during the enumeration.
See moreLinkingObjects
can only be used as a property onObject
models. Properties of this type must be declared aslet
and cannot bedynamic
.Declaration
Swift
public struct LinkingObjects<Element> where Element : Object
-
Migration
instances encapsulate information intended to facilitate a schema migration.A
See moreMigration
instance is passed into a user-definedMigrationBlock
block when updating the version of a Realm. This instance provides access to the old and new database schemas, the objects in the Realm, and provides functionality for modifying the Realm during the migration.Declaration
Swift
public struct Migration
-
Declaration
Swift
public struct PropertyChange
-
This class represents Realm model object schemas.
When using Realm,
ObjectSchema
instances allow performing migrations and introspecting the database’s schema.Object schemas map to tables in the core database.
See moreDeclaration
Swift
public struct ObjectSchema : CustomStringConvertible
-
Property
instances represent properties managed by a Realm in the context of an object schema. Such properties may be persisted to a Realm file or computed from other data in the Realm.When using Realm, property instances allow performing migrations and introspecting the database’s schema.
Property instances map to columns in the core database.
See moreDeclaration
Swift
public struct Property : CustomStringConvertible
-
An iterator for a
See moreRealmCollection
instance.Declaration
Swift
public struct RLMIterator<Element> : IteratorProtocol where Element : RealmCollectionValue
-
A type-erased
RealmCollection
.Instances of
See moreRealmCollection
forward operations to an opaque underlying collection having the sameElement
type.Declaration
Swift
public struct AnyRealmCollection<Element> : RealmCollection where Element : RealmCollectionValue
-
Results
is an auto-updating container type in Realm returned from object queries.Results
can be queried with the same predicates asList<Element>
, and you can chain queries to further filter query results.Results
always reflect the current state of the Realm on the current thread, including during write transactions on the current thread. The one exception to this is when usingfor...in
enumeration, which will always enumerate over the objects which matched the query when the enumeration is begun, even if some of them are deleted or modified to be excluded by the filter during the enumeration.Results
are lazily evaluated the first time they are accessed; they only run queries when the result of the query is requested. This means that chaining several temporaryResults
to sort and filter your data does not perform any unnecessary work processing the intermediate state.Once the results have been evaluated or a notification block has been added, the results are eagerly kept up-to-date, with the work done to keep them up-to-date done on a background thread whenever possible.
Results instances cannot be directly instantiated.
See moreDeclaration
Swift
public struct Results<Element> : Equatable where Element : RealmCollectionValue
-
Schema
instances represent collections of model object schemas managed by a Realm.When using Realm,
Schema
instances allow performing migrations and introspecting the database’s schema.Schemas map to collections of tables in the core database.
See moreDeclaration
Swift
public struct Schema : CustomStringConvertible
-
A
See moreSortDescriptor
stores a key path and a sort order for use withsorted(sortDescriptors:)
. It is similar toNSSortDescriptor
, but supports only the subset of functionality which can be efficiently run by Realm’s query engine.Declaration
Swift
public struct SortDescriptor
-
A
See moreSyncConfiguration
represents configuration parameters for Realms intended to sync with a Realm Object Server.Declaration
Swift
public struct SyncConfiguration
-
A
See moreSyncCredentials
represents data that uniquely identifies a Realm Object Server user.Declaration
Swift
public struct SyncCredentials
-
SyncSubscription
represents a subscription to a set of objects in a synced Realm.When partial sync is enabled for a synced Realm, the only objects that the server synchronizes to the client are those that match a sync subscription registered by that client. A subscription consists of of a query (represented by a
Results
) and an optional name.Changes to the state of the subscription can be observed using
SyncSubscription.observe(_:options:_:)
.Subscriptions are created using
See moreResults.subscribe()
orResults.subscribe(named:)
.Declaration
Swift
public struct SyncSubscription : RealmCollectionValue
-
A description of the actual privileges which apply to a Realm.
This is a combination of all of the privileges granted to all of the Roles which the current User is a member of, obtained by calling
realm.getPrivileges()
.By default, all operations are permitted, and each privilege field indicates an operation which may be forbidden.
See moreDeclaration
Swift
public struct RealmPrivileges : OptionSet, CustomDebugStringConvertible
-
A description of the actual privileges which apply to a Class within a Realm.
This is a combination of all of the privileges granted to all of the Roles which the current User is a member of, obtained by calling
realm.getPrivileges(ObjectClass.self)
orrealm.getPrivileges(forClassNamed: "className")
By default, all operations are permitted, and each privilege field indicates an operation which may be forbidden.
See moreDeclaration
Swift
public struct ClassPrivileges : OptionSet, CustomDebugStringConvertible
-
A description of the actual privileges which apply to a specific Object.
This is a combination of all of the privileges granted to all of the Roles which the current User is a member of, obtained by calling
realm.getPrivileges(object)
.By default, all operations are permitted, and each privilege field indicates an operation which may be forbidden.
See moreDeclaration
Swift
public struct ObjectPrivileges : OptionSet, CustomDebugStringConvertible
-
An object intended to be passed between threads containing a thread-safe reference to its thread-confined object.
To resolve a thread-safe reference on a target Realm on a different thread, pass to
Realm.resolve(_:)
.Warning
A
ThreadSafeReference
object must be resolved at most once. Failing to resolve aThreadSafeReference
will result in the source version of the Realm being pinned until the reference is deallocated.Note
Prefer short-lived
ThreadSafeReference
s as the data for the version of the source Realm will be retained until all references have been resolved or deallocated.See
Declaration
Swift
public struct ThreadSafeReference<Confined> where Confined : ThreadConfined