Classes
The following classes are available globally.
-
RLMArrayis the container type in Realm used to define to-many relationships.Unlike an
NSArray,RLMArrays hold a single type, specified by theobjectClassNameproperty. This is referred to in these docs as the “type” of the array.When declaring an
RLMArrayproperty, the type must be marked as conforming to a protocol by the same name as the objects it should contain (see theRLM_ARRAY_TYPEmacro). In addition, the property can be declared using Objective-C generics for better compile-time type safety.RLM_ARRAY_TYPE(ObjectType) ... @property RLMArray<ObjectType *><ObjectType> *arrayOfObjectTypes;RLMArrays can be queried with the same predicates asRLMObjectandRLMResults.RLMArrays cannot be created directly.RLMArrayproperties onRLMObjects are lazily created when accessed, or can be obtained by querying a Realm.Key-Value Observing
RLMArraysupports array key-value observing onRLMArrayproperties onRLMObjectsubclasses, and theinvalidatedproperty onRLMArrayinstances themselves is key-value observing compliant when theRLMArrayis attached to a managedRLMObject(RLMArrays on unmanagedRLMObjects will never become invalidated).Because
See moreRLMArrays are attached to the object which they are a property of, they do not require using the mutable collection proxy objects from-mutableArrayValueForKey:or KVC-compatible mutation methods on the containing object. Instead, you can call the mutation methods on theRLMArraydirectly.Declaration
Objective-C
@interface RLMArray <RLMObjectType : RLMObject *> : NSObject<RLMCollection,NSFastEnumeration>Swift
class RLMArray
-
An
RLMSortDescriptorstores a property name and a sort order for use withsortedResultsUsingDescriptors:. It is similar toNSSortDescriptor, but supports only the subset of functionality which can be efficiently run by Realm’s query engine.
See moreRLMSortDescriptorinstances are immutable.Declaration
Objective-C
@interface RLMSortDescriptor : NSObjectSwift
class RLMSortDescriptor : NSObject -
A
RLMCollectionChangeobject encapsulates information about changes to collections that are reported by Realm notifications.RLMCollectionChangeis passed to the notification blocks registered with-addNotificationBlockonRLMArrayandRLMResults, and reports what rows in the collection changed since the last time the notification block was called.The change information is available in two formats: a simple array of row indices in the collection for each type of change, and an array of index paths in a requested section suitable for passing directly to
UITableView‘s batch update methods. A complete example of updating aUITableViewnamedtv:[tv beginUpdates]; [tv deleteRowsAtIndexPaths:[changes deletionsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic]; [tv insertRowsAtIndexPaths:[changes insertionsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic]; [tv reloadRowsAtIndexPaths:[changes modificationsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic]; [tv endUpdates];All of the arrays in an
See moreRLMCollectionChangeare always sorted in ascending order.Declaration
Objective-C
@interface RLMCollectionChange : NSObjectSwift
class RLMCollectionChange : NSObject
-
RLMMigrationinstances encapsulate information intended to facilitate a schema migration.A
See moreRLMMigrationinstance is passed into a user-definedRLMMigrationBlockblock 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
Objective-C
@interface RLMMigration : NSObjectSwift
class RLMMigration : NSObject
-
RLMObjectis a base class for model objects representing data stored in Realms.Define your model classes by subclassing
RLMObjectand adding properties to be managed. Then instantiate and use your custom subclasses instead of using theRLMObjectclass directly.// Dog.h @interface Dog : RLMObject @property NSString *name; @property BOOL adopted; @end // Dog.m @implementation Dog @end //none neededSupported property types
NSStringNSInteger,int,long,float, anddoubleBOOLorboolNSDateNSDataNSNumber<X>, whereXis one ofRLMInt,RLMFloat,RLMDoubleorRLMBool, for optional number propertiesRLMObjectsubclasses, to model many-to-one relationships.RLMArray<X>, whereXis anRLMObjectsubclass, to model many-to-many relationships.
Querying
You can initiate queries directly via the class methods:
allObjects,objectsWhere:, andobjectsWithPredicate:. These methods allow you to easily query a custom subclass for instances of that class in the default Realm.To search in a Realm other than the default Realm, use the
allObjectsInRealm:,objectsInRealm:where:, andobjectsInRealm:withPredicate:class methods.See
RLMRealmRelationships
See our Cocoa guide for more details.
Key-Value Observing
All
RLMObjectproperties (including properties you create in subclasses) are Key-Value Observing compliant, except forrealmandobjectSchema.Keep the following tips in mind when observing Realm objects:
- Unlike
NSMutableArrayproperties,RLMArrayproperties do not require using the proxy object returned from-mutableArrayValueForKey:, or defining KVC mutation methods on the containing class. You can simply call methods on theRLMArraydirectly; any changes will be automatically observed by the containing object. - Unmanaged
RLMObjectinstances cannot be added to a Realm while they have any observed properties. - Modifying managed
RLMObjects within-observeValueForKeyPath:ofObject:change:context:is not recommended. Properties may change even when the Realm is not in a write transaction (for example, when-[RLMRealm refresh]is called after changes are made on a different thread), and notifications sent prior to the change being applied (whenNSKeyValueObservingOptionPrioris used) may be sent at times when you cannot begin a write transaction.
Declaration
Objective-C
@interface RLMObject : RLMObjectBase <RLMThreadConfined>Swift
class RLMObject : RLMObjectBase, RLMThreadConfined -
Declaration
Objective-C
@interface RLMPropertyChange : NSObjectSwift
class RLMPropertyChange : NSObject
-
This class represents Realm model object schemas.
When using Realm,
RLMObjectSchemainstances allow performing migrations and introspecting the database’s schema.Object schemas map to tables in the core database.
See moreDeclaration
Objective-C
@interface RLMObjectSchema : NSObject <NSCopying>Swift
class RLMObjectSchema : NSObject, NSCopying
-
RLMPropertyinstances 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 from the Realm.When using Realm,
RLMPropertyinstances allow performing migrations and introspecting the database’s schema.These property instances map to columns in the core database.
See moreDeclaration
Objective-C
@interface RLMProperty : NSObjectSwift
class RLMProperty : NSObject -
An
See moreRLMPropertyDescriptorinstance represents a specific property on a given class.Declaration
Objective-C
@interface RLMPropertyDescriptor : NSObjectSwift
class RLMPropertyDescriptor : NSObject
-
An
RLMRealmConfigurationinstance describes the different options used to create an instance of a Realm.RLMRealmConfigurationinstances are just plainNSObjects. UnlikeRLMRealms andRLMObjects, they can be freely shared between threads as long as you do not mutate them.Creating configuration objects for class subsets (by setting the
See moreobjectClassesproperty) can be expensive. Because of this, you will normally want to cache and reuse a single configuration object for each distinct configuration rather than creating a new object each time you open a Realm.Declaration
Objective-C
@interface RLMRealmConfiguration : NSObject <NSCopying>Swift
class RLMRealmConfiguration : NSObject, NSCopying
-
RLMResultsis an auto-updating container type in Realm returned from object queries. It represents the results of the query in the form of a collection of objects.RLMResultscan be queried using the same predicates asRLMObjectandRLMArray, and you can chain queries to further filter results.RLMResultsalways 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...infast 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.RLMResultsare 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 temporaryRLMResultsto 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.
See moreRLMResultscannot be directly instantiated.Declaration
Objective-C
@interface RLMResults <RLMObjectType : RLMObject *> : NSObject<RLMCollection,NSFastEnumeration>Swift
class RLMResults -
RLMLinkingObjectsis an auto-updating container type. It represents a collection of objects that link to its parent object.For more information, please see the
Inverse Relationships
section in the documentation.Declaration
Objective-C
@interface RLMLinkingObjects <RLMObjectType : RLMObject *> : RLMResultsSwift
class RLMLinkingObjects
-
RLMSchemainstances represent collections of model object schemas managed by a Realm.When using Realm,
RLMSchemainstances allow performing migrations and introspecting the database’s schema.Schemas map to collections of tables in the core database.
See moreDeclaration
Objective-C
@interface RLMSchema : NSObject <NSCopying>Swift
class RLMSchema : NSObject, NSCopying
-
A configuration object representing configuration state for a Realm which is intended to sync with a Realm Object Server.
See moreDeclaration
Objective-C
@interface RLMSyncConfiguration : NSObjectSwift
class RLMSyncConfiguration : NSObject
-
A singleton manager which serves as a central point for sync-related configuration.
See moreDeclaration
Objective-C
@interface RLMSyncManager : NSObjectSwift
class RLMSyncManager : NSObject
-
This model is used to reflect permissions.
It should be used in conjunction with a
RLMSyncUser‘s Permission Realm. You can only read this Realm. Use the objects in Management Realm to make request for modifications of permissions.See https://realm.io/docs/realm-object-server/#permissions for general documentation.
See more
-
This model is used for requesting changes to a Realm’s permissions.
It should be used in conjunction with an
RLMSyncUser‘s Management Realm.See https://realm.io/docs/realm-object-server/#permissions for general documentation.
See more
-
This model is used for offering permission changes to other users.
It should be used in conjunction with an
RLMSyncUser‘s Management Realm.See https://realm.io/docs/realm-object-server/#permissions for general documentation.
See more
-
This model is used to apply permission changes defined in the permission offer object represented by the specified token, which was created by another user’s
RLMSyncPermissionOfferobject.It should be used in conjunction with an
RLMSyncUser‘s Management Realm.See https://realm.io/docs/realm-object-server/#permissions for general documentation.
See more
-
A collection object representing the results of a permissions query.
This collection will automatically update its contents at the start of each runloop iteration, but the objects it vends are immutable.
Permission results objects are thread-confined, and should not be shared across threads.
See moreWarning
Permission results must only be fetched on threads that have an active run loop. In most cases this will be the main thread.Declaration
Objective-C
@interface RLMSyncPermissionResults : NSObject <NSFastEnumeration>Swift
class RLMSyncPermissionResults : NSObject, NSFastEnumeration
-
A value representing a permission granted to the specified user(s) to access the specified Realm(s).
RLMSyncPermissionValueis immutable and can be accessed from any thread.See https://realm.io/docs/realm-object-server/#permissions for general documentation.
See moreDeclaration
Objective-C
@interface RLMSyncPermissionValue : NSObjectSwift
class RLMSyncPermissionValue : NSObject
-
A token object corresponding to a progress notification block on a session object.
To stop notifications manually, call
-stopon it. Notifications should be stopped before the token goes out of scope or is destroyed.Declaration
Objective-C
@interface RLMProgressNotificationToken : RLMNotificationTokenSwift
class RLMProgressNotificationToken : RLMNotificationToken -
An object encapsulating a Realm Object Server
session
. Sessions represent the communication between the client (and a local Realm file on disk), and the server (and a remote Realm at a given URL stored on a Realm Object Server).Sessions are always created by the SDK and vended out through various APIs. The lifespans of sessions associated with Realms are managed automatically. Session objects can be accessed from any thread.
See moreDeclaration
Objective-C
@interface RLMSyncSession : NSObjectSwift
class RLMSyncSession : NSObject
-
A
RLMSyncUserinstance represents a single Realm Object Server user account.A user may have one or more credentials associated with it. These credentials uniquely identify the user to the authentication provider, and are used to sign into a Realm Object Server user account.
Note that user objects are only vended out via SDK APIs, and cannot be directly initialized. User objects can be accessed from any thread.
See moreDeclaration
Objective-C
@interface RLMSyncUser : NSObjectSwift
class RLMSyncUser : NSObject -
A data object representing information about a user that was retrieved from a user lookup call.
See moreDeclaration
Objective-C
@interface RLMSyncUserInfo : NSObjectSwift
class RLMSyncUserInfo : NSObject
-
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
-[RLMRealm resolveThreadSafeReference:].Warning
A
RLMThreadSafeReferenceobject must be resolved at most once. Failing to resolve aRLMThreadSafeReferencewill result in the source version of the Realm being pinned until the reference is deallocated.See moreNote
Prefer short-lived
RLMThreadSafeReferences as the data for the version of the source Realm will be retained until all references have been resolved or deallocated.Declaration
Objective-C
@interface RLMThreadSafeReference < __covariant Confined : id <RLMThreadConfined> > : NSObject @endSwift
class RLMThreadSafeReference
-
An
RLMRealminstance (also referred to asa Realm
) represents a Realm database.Realms can either be stored on disk (see
+[RLMRealm realmWithURL:]) or in memory (seeRLMRealmConfiguration).RLMRealminstances are cached internally, and constructing equivalentRLMRealmobjects (for example, by using the same path or identifier) multiple times on a single thread within a single iteration of the run loop will normally return the sameRLMRealmobject.If you specifically want to ensure an
RLMRealminstance 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.See moreWarning
RLMRealminstances are not thread safe and cannot be shared across threads or dispatch queues. Trying to do so will cause an exception to be thrown. You must call this method 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 all of its blocks on the same thread.Declaration
Objective-C
@interface RLMRealm : NSObject -
A token which is returned from methods which subscribe to changes to a Realm.
Change subscriptions in Realm return an
See moreRLMNotificationTokeninstance, which can be used to unsubscribe from the changes. You must store a strong reference to the token for as long as you want to continue to receive notifications. When you wish to stop, call the-stopmethod. Notifications are also stopped if the token is deallocated.Declaration
Objective-C
@interface RLMNotificationToken : NSObject
-
Opaque credentials representing a specific Realm Object Server user.
See moreDeclaration
Objective-C
@interface RLMSyncCredentials : NSObject
View on GitHub
Install in Dash
Classes Reference