Classes
The following classes are available globally.
-
A
Realminstance (also referred to asa Realm
) represents a Realm database.Realms can either be stored on disk (see
init(path:)) or in memory (seeConfiguration).Realminstances are cached internally, and constructing equivalentRealmobjects (for example, by using the same path or identifier) produces limited overhead.If you specifically want to ensure a
Realminstance 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.See moreWarning
Realminstances 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 final class Realm
-
LinkingObjectsis an auto-updating container type. It represents zero or more objects that are linked to its owning model object through a property relationship.LinkingObjectscan be queried with the same predicates asList<Element>andResults<Element>.LinkingObjectsalways 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...inenumeration, 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 moreLinkingObjectscan only be used as a property onObjectmodels. Properties of this type must be declared asletand cannot bedynamic.Declaration
Swift
public final class LinkingObjects<Element> : LinkingObjectsBase where Element : Object
-
Listis the container type in Realm used to define to-many relationships.Like Swift’s
Array,Listis a generic type that is parameterized on the type it stores. This can be either anObjectsubclass or one of the following types:Bool,Int,Int8,Int16,Int32,Int64,Float,Double,String,Data, andDate(and their optional versions)Unlike Swift’s native collections,
Lists are reference types, and are only immutable if the Realm that manages them is opened as read-only.Lists can be filtered and sorted with the same predicates as
Results<Element>.Properties of
See moreListtype defined onObjectsubclasses must be declared asletand cannot bedynamic.Declaration
Swift
public final class List<Element> : ListBase where Element : RealmCollectionValue
-
Objectis a class used to define Realm model objects.In Realm you define your model classes by subclassing
Objectand adding properties to be managed. You then instantiate and use your custom subclasses instead of using theObjectclass directly.class Dog: Object { @objc dynamic var name: String = "" @objc dynamic var adopted: Bool = false let siblings = List<Dog>() }Supported property types
String,NSStringIntInt8,Int16,Int32,Int64FloatDoubleBoolDate,NSDateData,NSDataRealmOptional<Value>for optional numeric propertiesObjectsubclasses, to model many-to-one relationshipsList<Element>, to model many-to-many relationships
String,NSString,Date,NSDate,Data,NSDataandObjectsubclass properties can be declared as optional.Int,Int8,Int16,Int32,Int64,Float,Double,Bool, andListproperties cannot. To store an optional number, useRealmOptional<Int>,RealmOptional<Float>,RealmOptional<Double>, orRealmOptional<Bool>instead, which wraps an optional numeric value.All property types except for
ListandRealmOptionalmust be declared as@objc dynamic var.ListandRealmOptionalproperties must be declared as non-dynamicletproperties. Swiftlazyproperties 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.Relationships
See our Cocoa guide for more details.
See moreDeclaration
Swift
@objc(RealmSwiftObject) open class Object : RLMObjectBase, ThreadConfined, RealmCollectionValue
-
A
RealmOptionalinstance represents an optional value for types that can’t be directly declared as@objcin Swift, such asInt,Float,Double, andBool.To change the underlying value stored by a
See moreRealmOptionalinstance, mutate the instance’svalueproperty.Declaration
Swift
public final class RealmOptional<Value> : RLMOptionalBase where Value : RealmOptionalType
-
A type-erased
RealmCollection.Instances of
See moreRealmCollectionforward operations to an opaque underlying collection having the sameElementtype.Declaration
Swift
public final class AnyRealmCollection<Element> : RealmCollection where Element : RealmCollectionValue
-
Resultsis an auto-updating container type in Realm returned from object queries.Resultscan be queried with the same predicates asList<Element>, and you can chain queries to further filter query results.Resultsalways 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...inenumeration, 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.Resultsare 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 temporaryResultsto 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 final class Results<Element> : NSObject, NSFastEnumeration where Element : RealmCollectionValue
-
SyncSubscriptionrepresents 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 final class SyncSubscription<T> : RealmCollectionValue where T : RealmCollectionValue
-
A permission which can be applied to a Realm, Class, or specific Object.
Permissions are applied by adding the permission to the RealmPermission singleton object, the ClassPermission object for the desired class, or to a user-defined List
See moreproperty on a specific Object instance. The meaning of each of the properties of Permission depend on what the permission is applied to, and so are left undocumented here. See RealmPrivileges,ClassPrivileges, andObjectPrivilegesfor details about what each of the properties mean when applied to that type.Declaration
Swift
@objc(RealmSwiftPermission) public class Permission : Object -
A Role within the permissions system.
A Role consists of a name for the role and a list of users which are members of the role. Roles are granted privileges on Realms, Classes and Objects, and in turn grant those privileges to all users which are members of the role.
A role named
See moreeveryone
is automatically created in new Realms, and all new users which connect to the Realm are automatically added to it. Any other roles you wish to use are managed as normal Realm objects.Declaration
Swift
@objc(RealmSwiftPermissionRole) public class PermissionRole : Object -
A representation of a sync user within the permissions system.
PermissionUser objects are created automatically for each sync user which connects to a Realm, and can also be created manually if you wish to grant permissions to a user which has not yet connected to this Realm. When creating a PermissionUser manually, you must also manually add it to the
See moreeveryone
Role.Declaration
Swift
@objc(RealmSwiftPermissionUser) public class PermissionUser : Object -
A singleton object which describes Realm-wide permissions.
An object of this type is automatically created in the Realm for you, and more objects cannot be created manually.
See
See moreRealmPrivilegesfor the meaning of permissions applied to a Realm.Declaration
Swift
@objc(RealmSwiftRealmPermission) public class RealmPermission : Object
-
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
ThreadSafeReferenceobject must be resolved at most once. Failing to resolve aThreadSafeReferencewill 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 moreSee
Declaration
Swift
public class ThreadSafeReference<Confined> where Confined : ThreadConfined
View on GitHub
Install in Dash
Classes Reference