Classes
The following classes 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 final class 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<T>
andResults<T>
.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 final class LinkingObjects<T: Object>: LinkingObjectsBase
-
List
is the container type in Realm used to define to-many relationships.Like Swift’s
Array
,List
is a generic type that is parameterized on the type ofObject
it stores.Unlike Swift’s native collections,
List
s 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<T>
.Properties of
See moreList
type defined onObject
subclasses must be declared aslet
and cannot bedynamic
.Declaration
Swift
public final class List<T: Object>: ListBase
-
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 final class Migration
-
Object
is a class used to define Realm model objects.In Realm you define your model classes by subclassing
Object
and adding properties to be managed. You then instantiate and use your custom subclasses instead of using theObject
class directly.class Dog: Object { dynamic var name: String = "" dynamic var adopted: Bool = false let siblings = List<Dog>() }
Supported property types
String
,NSString
Int
Int8
,Int16
,Int32
,Int64
Float
Double
Bool
Date
,NSDate
Data
,NSData
RealmOptional<T>
for optional numeric propertiesObject
subclasses, to model many-to-one relationshipsList<T>
, to model many-to-many relationships
String
,NSString
,Date
,NSDate
,Data
,NSData
andObject
subclass properties can be declared as optional.Int
,Int8
,Int16
,Int32
,Int64
,Float
,Double
,Bool
, andList
properties 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
List
andRealmOptional
must be declared asdynamic var
.List
andRealmOptional
properties must be declared as non-dynamiclet
properties. Swiftlazy
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.Relationships
See our Cocoa guide for more details.
See moreDeclaration
Swift
open class Object: RLMObjectBase
-
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 final class ObjectSchema: CustomStringConvertible
-
A
RealmOptional
instance represents an optional value for types that can’t be directly declared asdynamic
in Swift, such asInt
,Float
,Double
, andBool
.To change the underlying value stored by a
See moreRealmOptional
instance, mutate the instance’svalue
property.Declaration
Swift
public final class RealmOptional<T: RealmOptionalType>: RLMOptionalBase
-
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 final class Property: CustomStringConvertible
-
An iterator for a
See moreRealmCollection
instance.Declaration
Swift
public final class RLMIterator<T: Object>: IteratorProtocol
-
A type-erased
RealmCollection
.Instances of
See moreRealmCollection
forward operations to an opaque underlying collection having the sameElement
type.Declaration
Swift
public final class AnyRealmCollection<T: Object>: RealmCollection
-
Results
is an auto-updating container type in Realm returned from object queries.Results
can be queried with the same predicates asList<T>
, 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 final class Results<T: Object>: NSObject, NSFastEnumeration
-
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 final class Schema: CustomStringConvertible
-
This model is used for requesting changes to a Realm’s permissions.
It should be used in conjunction with an
SyncUser
’s management Realm.See https://realm.io/docs/realm-object-server/#permissions for general documentation.
See moreDeclaration
Swift
public final class SyncPermissionChange: Object