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 the type of the List.

    Lists can be filtered and sorted with the same predicates as Results<T>.

    When added as a property on Object models, the property must be declared as let and cannot be dynamic.

    See more

    Declaration

    Swift

    public final class List<T: Object>: ListBase
  • 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 properties
    • Object subclasses for to-one relationships
    • List<T: Object> for to-many relationships

    String, NSString, NSDate, NSData and Object subclass properties can be optional. Int, Int8, Int16, Int32, Int64, Float, Double, Bool and List properties cannot. To store an optional number, instead use RealmOptional<Int>, RealmOptional<Float>, RealmOptional<Double>, or RealmOptional<Bool> instead, which wraps an optional value of the generic type.

    All property types except for List and RealmOptional must be declared as dynamic var. List and RealmOptional properties must be declared as non-dynamic let properties.

    Querying

    You can gets Results of an Object subclass via the objects(_:) instance method on Realm.

    Relationships

    See our Cocoa guide for more details.

    See more

    Declaration

    Swift

    public class Object: RLMObjectBase
  • This class represents Realm model object schemas.

    When using Realm, ObjectSchema objects allow performing migrations and introspecting the database’s schema.

    ObjectSchemas map to tables in the core database.

    See more

    Declaration

    Swift

    public final class ObjectSchema: CustomStringConvertible
  • A RealmOptional represents a optional value for types that can’t be directly declared as dynamic in Swift, such as Ints, Float, Double, and Bool.

    It encapsulates a value in its value property, which is the only way to mutate a RealmOptional property on an Object.

    See more

    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 more

    Declaration

    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 (see Configuration).

    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.
    See more

    Declaration

    Swift

    public final class Realm
  • LinkingObjects is an auto-updating container type that represents a collection of objects that link to a given object.

    LinkingObjects can be queried with the same predicates as List<T> and Results<T>.

    LinkingObjects 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 linking objects 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. The property must be declared as let and cannot be dynamic.

    See more

    Declaration

    Swift

    public final class LinkingObjects<T: Object>: LinkingObjectsBase
  • 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 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 initially lazily evaluated, and 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 extra 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 cannot be created directly.

    See more

    Declaration

    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.

    Schemas map to collections of tables in the core database.

    See more

    Declaration

    Swift

    public final class Schema: CustomStringConvertible