Inherits from NSObject
Declared in RLMRealm.h
RLMRealm.mm

Properties

autorefresh

Set to YES to automatically update this Realm when changes happen in other threads.

@property (nonatomic) BOOL autorefresh

Discussion

If set to NO, you must manually call refresh on the Realm to update it to get the lastest version. Notifications are sent immediately when a change is available whether or not the Realm is automatically updated.

Defaults to YES on the main thread, NO on all others.

Declared In

RLMRealm.h

path

Path to the file where this Realm is persisted.

@property (nonatomic, readonly) NSString *path

Declared In

RLMRealm.h

readOnly

Indicates if this Realm is read only

@property (nonatomic, readonly, getter=isReadOnly) BOOL readOnly

Return Value

Boolean value indicating if this RLMRealm instance is readonly.

Declared In

RLMRealm.h

schema

The RLMSchema used by this RLMRealm.

@property (nonatomic, readonly) RLMSchema *schema

Declared In

RLMRealm.h

Class Methods

defaultRealm

Obtains an instance of the default Realm.

+ (instancetype)defaultRealm

Return Value

The default RLMRealm instance for the current thread.

Discussion

RLMRealm instances are reused when this is called multiple times from the same thread. The default RLMRealm is persisted as default.realm under the Documents directory of your Application.

Warning: RLMRealm instances are not thread safe and can not be shared across threads or dispatch queues. You must get a separate RLMRealm instance for each thread and queue.

Declared In

RLMRealm.h

defaultRealmPath

Returns the location of the default Realm as a string.

+ (NSString *)defaultRealmPath

Return Value

Location of the default Realm.

Discussion

~/Documents/default.realm on OSX.

default.realm in your application’s documents directory on iOS.

See Also

Declared In

RLMRealm.h

migrateDefaultRealmWithBlock:

Performs a migration on the default Realm.

+ (NSError *)migrateDefaultRealmWithBlock:(RLMMigrationBlock)block

Parameters

block

The block which migrates the Realm to the current version.

Return Value

The error that occured while applying the migration if any.

Discussion

Must be called before the default Realm is accessed (otherwise throws). If the default Realm is at a version other than version, the migration is applied.

See Also

Declared In

RLMRealm.h

migrateRealmAtPath:withBlock:

Performs a migration on a Realm at a path.

+ (NSError *)migrateRealmAtPath:(NSString *)realmPath withBlock:(RLMMigrationBlock)block

Parameters

realmPath

The path of the Realm to migrate.

block

The block which migrates the Realm to the current version.

Return Value

The error that occured while applying the migration if any.

Discussion

Must be called before the Realm at realmPath is accessed (otherwise throws). If the Realm is at a version other than version, the migration is applied.

See Also

Declared In

RLMRealm.h

realmWithPath:

Obtains an RLMRealm instance persisted at a specific file.

+ (instancetype)realmWithPath:(NSString *)path

Parameters

path

Path to the file you want the data saved in.

Return Value

An RLMRealm instance.

Discussion

RLMRealm instances are reused when this is called multiple times from the same thread.

Warning: RLMRealm instances are not thread safe and can not be shared across threads or dispatch queues. You must get a separate RLMRealm instance for each thread and queue.

Declared In

RLMRealm.h

realmWithPath:readOnly:error:

Obtains an RLMRealm instance with persistence to a specific file with options.

+ (instancetype)realmWithPath:(NSString *)path readOnly:(BOOL)readonly error:(NSError **)error

Parameters

path

Path to the file you want the data saved in.

readonly

BOOL indicating if this Realm is readonly (must use for readonly files)

error

Pass-by-reference for errors.

Return Value

An RLMRealm instance.

Discussion

Warning: RLMRealm instances are not thread safe and can not be shared across threads or dispatch queues. You must get a separate RLMRealm instance for each thread and queue.

Declared In

RLMRealm.h

useInMemoryDefaultRealm

Make the default Realm in-memory only

+ (void)useInMemoryDefaultRealm

Discussion

By default, the default Realm is persisted to disk unless this method is called.

Warning: This must be called before any Realm instances are obtained (otherwise throws).

Declared In

RLMRealm.h

Instance Methods

addNotificationBlock:

Add a notification handler for changes in this RLMRealm.

- (RLMNotificationToken *)addNotificationBlock:(RLMNotificationBlock)block

Parameters

block

A block which is called to process RLMRealm notifications.

Return Value

A token object which can later be passed to removeNotification:. to remove this notification.

Discussion

The block has the following definition:

 typedef void(^RLMNotificationBlock)(NSString *notification, RLMRealm *realm);

It receives the following parameters:

  • NSString *notification: The name of the incoming notification. RLMRealmDidChangeNotification is the only notification currently supported.
  • RLMRealm *realm: The realm for which this notification occurred

Declared In

RLMRealm.h

addObject:

Adds an object to be persisted it in this Realm.

- (void)addObject:(RLMObject *)object

Parameters

object

Object to be added to this Realm.

Discussion

Once added, this object can be retrieved using the objectsWhere: selectors on RLMRealm and on subclasses of RLMObject. When added, all linked (child) objects referenced by this object will also be added to the Realm if they are not already in it. If linked objects already belong to a different Realm an exception will be thrown.

Declared In

RLMRealm.h

addObjectsFromArray:

Adds objects in the given array to be persisted it in this Realm.

- (void)addObjectsFromArray:(id)array

Parameters

array

NSArray or RLMArray of RLMObjects (or subclasses) to be added to this Realm.

Discussion

This is the equivalent of addObject: except for an array of objects.

See Also

Declared In

RLMRealm.h

beginWriteTransaction

Begins a write transaction in an RLMRealm.

- (void)beginWriteTransaction

Discussion

Only one write transaction can be open at a time. Calls to beginWriteTransaction from RLMRealm instances in other threads will block until the current write transaction terminates.

In the case writes were made in other threads or processes to other instances of the same realm, the RLMRealm on which beginWriteTransaction is called and all outstanding objects obtained from this RLMRealm are updated to the latest Realm version when this method is called (if this happens it will also trigger a notification).

Declared In

RLMRealm.h

commitWriteTransaction

Commits all writes operations in the current write transaction.

- (void)commitWriteTransaction

Discussion

After this is called the RLMRealm reverts back to being read-only.

Declared In

RLMRealm.h

deleteObject:

Delete an object from this Realm.

- (void)deleteObject:(RLMObject *)object

Parameters

object

Object to be deleted from this Realm.

Declared In

RLMRealm.h

deleteObjects:

Delete an NSArray or RLMArray of objects from this Realm.

- (void)deleteObjects:(id)array

Parameters

array

RLMArray or NSArray of RLMObjects to be deleted.

Declared In

RLMRealm.h

refresh

Update an RLMRealm and outstanding objects to point to the most recent data for this RLMRealm.

- (void)refresh

Declared In

RLMRealm.h

removeNotification:

Remove a previously registered notification handler using the token returned from addNotificationBlock:

- (void)removeNotification:(RLMNotificationToken *)notificationToken

Parameters

notificationToken

The token returned from addNotificationBlock: corresponding to the notification block to remove.

Declared In

RLMRealm.h

transactionWithBlock:

Helper to perform a block within a transaction.

- (void)transactionWithBlock:(void ( ^ ) ( void ))block

Declared In

RLMRealm.h