Structures

The following structures are available globally.

  • A Realm instance (also referred to as a Realm) represents a Realm database.

    Realms can either be stored on disk (see init(path:)) or in memory (see Configuration).

    Realm instances are cached internally, and constructing equivalent Realm 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 an autoreleasepool {} 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.
    See more

    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 as List<Element> and Results<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 using for...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.

    LinkingObjects can only be used as a property on Object models. Properties of this type must be declared as let and cannot be dynamic.

    See more

    Declaration

    Swift

    public struct LinkingObjects<Element> where Element : Object
  • Migration instances encapsulate information intended to facilitate a schema migration.

    A Migration instance is passed into a user-defined MigrationBlock 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.

    See more

    Declaration

    Swift

    public struct Migration
  • 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 more

    Declaration

    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 more

    Declaration

    Swift

    public struct Property : CustomStringConvertible
  • Results is an auto-updating container type in Realm returned from object queries.

    Results can be queried with the same predicates as List<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 using for...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 temporary Results 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 more

    Declaration

    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 more

    Declaration

    Swift

    public struct Schema : CustomStringConvertible
  • A SortDescriptor stores a key path and a sort order for use with sorted(sortDescriptors:). It is similar to NSSortDescriptor, but supports only the subset of functionality which can be efficiently run by Realm’s query engine.

    See more

    Declaration

    Swift

    public struct SortDescriptor
  • A SyncConfiguration represents configuration parameters for Realms intended to sync with a Realm Object Server.

    See more

    Declaration

    Swift

    public struct SyncConfiguration
  • A SyncCredentials represents data that uniquely identifies a Realm Object Server user.

    See more

    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 Results.subscribe() or Results.subscribe(named:).

    See more

    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 more

    Declaration

    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) or realm.getPrivileges(forClassNamed: "className")

    By default, all operations are permitted, and each privilege field indicates an operation which may be forbidden.

    See more

    Declaration

    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 more

    Declaration

    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 a ThreadSafeReference will result in the source version of the Realm being pinned until the reference is deallocated.

    Note

    Prefer short-lived ThreadSafeReferences as the data for the version of the source Realm will be retained until all references have been resolved or deallocated.

    See more

    Declaration

    Swift

    public struct ThreadSafeReference<Confined> where Confined : ThreadConfined