Latest 0.2.0
License MIT
Platforms ios 10.0, watchos 3.0, tvos 10.0, requires ARC
Dependencies Realm

CI Status

SMWRealm makes it even easier to create, read, update, and delete RLMObjects from different threads.
Simply pass around the SMWRealmKey object betweeen different threads, and use its methods to communicate with its RLMObject.
This takes the thinking out of mulithreading with Realm.


To run the example project, clone the repo, and run pod install from the Example directory first.


SMWRealm requires iOS 7.0 and above or OS X 10.9 and above.

SMWRealm also requires the thirdy-party open source library Realm


To run the example project run git clone
Then open the Example directory and run pod install
Now you can open and run the project in Example/SMWRealm.xcworkspace.


SMWRealm is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SMWRealm"


Sam Meech-Ward, [email protected]


SMWRealm is available under the MIT license. See the LICENSE file for more info.

How to use

Any RLMObject that uses the SMWRealmKey must have a valid primary key.

Import the SMWRealm header

#import <SMWRealm/SMWRealm.h>

Setup your RLMObject as normal.

Person *person = [[Person alloc] init];
person.firstName = @"Sam";
person.lastName = @"Meech-Ward";

Then save to a realm using the SMWRealmKey object

RLMRealm *realm = [RLMRealm defaultRealm];
SMWRealmKey<Person *> *personKey = [SMWRealmKey createOrUpdateObject:person inRealm:realm];

Now you can pass this SMWRealmKey object around different threads and use its methods to read and update the RLMObject.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  [personKey updateRealmObject:^(SMWRealmPerson *object, RLMRealm *realm) {
    object.firstName = @"New First Name";
    object.lastName = @"New Last Name";

SMWRealmKey methods

- (instancetype)initWithRealmObject:(RLMObject *)realmObject;
- (void)readRealmObject:(void(^)(RLMObjectType _Nullable object))block;
- (void)updateRealmObject:(void(^)(RLMObjectType _Nullable object, RLMRealm * _Nullable realm))block;
- (void)deleteRealmObject;
- (BOOL)isEqualToKey:(nullable id)object;

When deleting related objects, it’s convenient to use the update function

[key updateRealmObject:^(Person * _Nullable object, RLMRealm * _Nullable realm) {
    Dog *dog =;
    [realm deleteObjects:@[person, dog]];

Latest podspec

    "name": "SMWRealm",
    "version": "0.2.0",
    "summary": "Make it easier to pass around, read, and modify realm objects accross multiple threads.",
    "description": "SMWRealm uses the primary keys of RMLObjects and thread safe SMWRealmKey objects to easily use RLMObjects accorss multiple threads.",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "Sam Meech-Ward": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.0"
    "platforms": {
        "ios": "10.0",
        "watchos": "3.0",
        "tvos": "10.0"
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "dependencies": {
        "Realm": [

Pin It on Pinterest

Share This