RLMRealm Class Reference
| Inherits from | NSObject |
| Declared in | RLMRealm.h RLMRealm.mm |
Tasks
Creating & Initializing a Realm
-
+ defaultRealm -
+ realmWithPath: -
+ realmWithPath:readOnly:error: -
+ useInMemoryDefaultRealm -
pathproperty -
readOnlyproperty -
schemaproperty
Default Realm Path
Receiving Notification when a Realm Changes
Writing to a Realm
-
– beginWriteTransaction -
– commitWriteTransaction -
– transactionWithBlock: -
– refresh -
autorefreshproperty
Adding and Removing Objects from a Realm
Properties
autorefresh
Set to YES to automatically update this Realm when changes happen in other threads.
@property (nonatomic) BOOL autorefreshDiscussion
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.hpath
Path to the file where this Realm is persisted.
@property (nonatomic, readonly) NSString *pathDeclared In
RLMRealm.hreadOnly
Indicates if this Realm is read only
@property (nonatomic, readonly, getter=isReadOnly) BOOL readOnlyReturn Value
Boolean value indicating if this RLMRealm instance is readonly.
Declared In
RLMRealm.hschema
The RLMSchema used by this RLMRealm.
@property (nonatomic, readonly) RLMSchema *schemaDeclared In
RLMRealm.hClass Methods
defaultRealm
Obtains an instance of the default Realm.
+ (instancetype)defaultRealmReturn 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.hdefaultRealmPath
Returns the location of the default Realm as a string.
+ (NSString *)defaultRealmPathReturn 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.hmigrateDefaultRealmWithBlock:
Performs a migration on the default Realm.
+ (NSError *)migrateDefaultRealmWithBlock:(RLMMigrationBlock)blockParameters
- 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.hmigrateRealmAtPath:withBlock:
Performs a migration on a Realm at a path.
+ (NSError *)migrateRealmAtPath:(NSString *)realmPath withBlock:(RLMMigrationBlock)blockParameters
- 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.hrealmWithPath:
Obtains an RLMRealm instance persisted at a specific file.
+ (instancetype)realmWithPath:(NSString *)pathParameters
- 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.hrealmWithPath:readOnly:error:
Obtains an RLMRealm instance with persistence to a specific file with options.
+ (instancetype)realmWithPath:(NSString *)path readOnly:(BOOL)readonly error:(NSError **)errorParameters
- 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.hInstance Methods
addNotificationBlock:
Add a notification handler for changes in this RLMRealm.
- (RLMNotificationToken *)addNotificationBlock:(RLMNotificationBlock)blockParameters
- 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.haddObject:
Adds an object to be persisted it in this Realm.
- (void)addObject:(RLMObject *)objectParameters
- 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.haddObjectsFromArray:
Adds objects in the given array to be persisted it in this Realm.
- (void)addObjectsFromArray:(id)arrayParameters
- 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.hbeginWriteTransaction
Begins a write transaction in an RLMRealm.
- (void)beginWriteTransactionDiscussion
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.hcommitWriteTransaction
Commits all writes operations in the current write transaction.
- (void)commitWriteTransactionDiscussion
After this is called the RLMRealm reverts back to being read-only.
Declared In
RLMRealm.hdeleteObject:
Delete an object from this Realm.
- (void)deleteObject:(RLMObject *)objectParameters
- object
Object to be deleted from this Realm.
Declared In
RLMRealm.hdeleteObjects:
Delete an NSArray or RLMArray of objects from this Realm.
- (void)deleteObjects:(id)arrayParameters
- array
RLMArray or NSArray of RLMObjects to be deleted.
Declared In
RLMRealm.hrefresh
Update an RLMRealm and outstanding objects to point to the most recent data for this RLMRealm.
- (void)refreshDeclared In
RLMRealm.hremoveNotification:
Remove a previously registered notification handler using the token returned from addNotificationBlock:
- (void)removeNotification:(RLMNotificationToken *)notificationTokenParameters
- notificationToken
The token returned from addNotificationBlock: corresponding to the notification block to remove.
Declared In
RLMRealm.h