Classes
The following classes are available globally.
-
List<T>
is the container type in Realm used to define to-many relationships.Lists hold a single
Object
subclass (T
) which defines thetype
of the List.Lists can be filtered and sorted with the same predicates as
Results<T>
.When added as a property on
See moreObject
models, the property must be declared aslet
and cannot bedynamic
.Declaration
Swift
public final class List<T: Object>: ListBase
-
Migration
is the object passed into a user-definedMigrationBlock
when updating the version of aRealm
instance.This object provides access to the previous and current
See moreSchema
s for this migration.Declaration
Swift
public final class Migration
-
In Realm you define your model classes by subclassing
Object
and adding properties to be persisted. You then instantiate and use your custom subclasses instead of using the Object 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
NSDate
NSData
RealmOptional<T>
for optional numeric propertiesObject
subclasses for to-one relationshipsList<T: Object>
for to-many relationships
String
,NSString
,NSDate
,NSData
andObject
subclass properties can be optional.Int
,Int8
, Int16, Int32
,Int64
,Float
,Double
,Bool
andList
properties cannot. To store an optional number, instead useRealmOptional<Int>
,RealmOptional<Float>
,RealmOptional<Double>
, orRealmOptional<Bool>
instead, which wraps an optional value of the generic type.All property types except for
List
andRealmOptional
must be declared asdynamic var
.List
andRealmOptional
properties must be declared as non-dynamiclet
properties.Querying
You can gets
Results
of an Object subclass via theobjects(_:)
instance method onRealm
.Relationships
See our Cocoa guide for more details.
See moreDeclaration
Swift
public class Object: RLMObjectBase
-
A
RealmOptional
represents a optional value for types that can’t be directly declared asdynamic
in Swift, such asInt
s,Float
,Double
, andBool
.It encapsulates a value in its
See morevalue
property, which is the only way to mutate aRealmOptional
property on anObject
.Declaration
Swift
public final class RealmOptional<T: RealmOptionalType>: RLMOptionalBase
-
This class represents properties persisted to Realm in an
ObjectSchema
.When using Realm,
Property
objects allow performing migrations and introspecting the database’s schema.These properties map to columns in the core database.
See moreDeclaration
Swift
public final class Property: CustomStringConvertible
-
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 (seeConfiguration
).Realm instances are cached internally, and constructing equivalent Realm objects (with the same path or identifier) produces limited overhead.
If you specifically want to ensure a Realm object 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 can not be shared across threads or dispatch queues. You must construct a new instance on each thread you want to interact with the realm on. For dispatch queues, this means that you must call it in each block which is dispatched, as a queue is not guaranteed to run on a consistent thread.Declaration
Swift
public final class Realm
-
Encapsulates iteration state and interface for iteration over a
See moreRealmCollectionType
.Declaration
Swift
public final class RLMGenerator<T: Object>: GeneratorType
-
A type-erased
RealmCollectionType
.Forwards operations to an arbitrary underlying collection having the same Element type, hiding the specifics of the underlying
See moreRealmCollectionType
.Declaration
Swift
public final class AnyRealmCollection<T: Object>: RealmCollectionType
-
Results
is an auto-updating container type in Realm returned from object queries.Results can be queried with the same predicates as
List<T>
and you can chain queries to further filter query results.Results cannot be created directly.
See moreDeclaration
Swift
public final class Results<T: Object>: ResultsBase
-
This class represents the collection of model object schemas persisted to Realm.
When using Realm,
Schema
objects allow performing migrations and introspecting the database’s schema.
See moreSchema
s map to collections of tables in the core database.Declaration
Swift
public final class Schema: CustomStringConvertible