Latest 0.9.9
Homepage https://github.com/yusuga/YSRealmStore
License MIT
Platforms ios 7.0, requires ARC
Dependencies Realm

Simple wrapper for Realm Cocoa.

Features

  • Support Realm Cocoa (0.98.3)
  • Async/Cancel operation.

Installation

pod 'YSRealmStore'

Usage

Initialize

RLMRealmConfiguration *configuration = [[RLMRealmConfiguration alloc] init];
configuration.path = [YSRealmStore realmPathWithFileName:@"twitter"];

configuration.objectClasses = @[[Tweet class],
                                [User class],
                                [Entities class],
                                [Url class],
                                [Mention class]];

configuration.schemaVersion = 2;
configuration.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
    /* Migration */
};

TwitterRealmStore *store =  [[TwitterRealmStore alloc] initWithConfiguration:configuration];

Write transaction

Transaction

/* Sync */
[store writeTransactionWithWriteBlock:^(YSRealmWriteTransaction *transaction, RLMRealm *realm) {
    // Can be operated for the realm. (Main thread)
    [realm addOrUpdateObject:[[Tweet alloc] initWithObject:obj]];
}];

/* Async */
[store writeTransactionWithWriteBlock:^(YSRealmWriteTransaction *transaction, RLMRealm *realm) {
    // Can be operated for the realm. (Background thread)
    [realm addOrUpdateObject:[[Tweet alloc] initWithObject:obj]];
} completion:^(YSRealmStore *store, YSRealmWriteTransaction *transaction) {

}];

Cancel

YSRealmWriteTransaction *transaction = [store writeTransactionWithWriteBlock:writeBlock
                                                                  completion:completion];
[transaction cancel];

Operation

Add

/* Sync */
[store writeObjectsWithObjectsBlock:^id(YSRealmOperation *operation, RLMRealm *realm) {
    // Can be operated for the realm. (Main thread)
    return [[Tweet alloc] initWithObject:tweetJsonObj];
}];

/* Async */
[store writeObjectsWithObjectsBlock:^id(YSRealmOperation *operation, RLMRealm *realm) {
    // Can be operated for the realm. (Background thread)
    return [[Tweet alloc] initWithObject:tweetJsonObj];
} completion:^(YSRealmStore *store, YSRealmOperation *operation) {

}];

Delete

/* Sync */
[store deleteObjectsWithObjectsBlock:^id(YSRealmOperation *operation, RLMRealm *realm) {
    // Can be operated for the realm. (Main thread)
    return [Tweet allObjects];
}];

/* Async */
[store deleteObjectsWithObjectsBlock:^id(YSRealmOperation *operation, RLMRealm *realm) {
    // Can be operated for the realm. (Background thread)
    return [Tweet allObjects];
} completion:^(YSRealmStore *store, YSRealmOperation *operation) {

}];

Fetch

*Fetched object is require primary key.

/* Async */
[store fetchObjectsWithObjectsBlock:^id(YSRealmOperation *operation, RLMRealm *realm) {
    // Can be operated for the realm. (Background thread)
    RLMResults *tweets = [Tweet allObjects];
    return [tweets sortedResultsUsingProperty:@"id" ascending:YES];
} completion:^(YSRealmStore *store, YSRealmOperation *operation, RLMRealm *realm, RLMResults *results) {

}];

Cancel

YSRealmOperation *operation = [store writeObjectsWithObjectsBlock:objectsBlock
                                                       completion:completion];

[operation cancel];

Latest podspec

{
    "name": "YSRealmStore",
    "version": "0.9.9",
    "summary": "Simple wrapper for Realm Cocoa.",
    "homepage": "https://github.com/yusuga/YSRealmStore",
    "license": "MIT",
    "authors": "Yu Sugawara",
    "social_media_url": "https://twitter.com/yusuga_",
    "source": {
        "git": "https://github.com/yusuga/YSRealmStore.git",
        "tag": "0.9.9"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source_files": "Classes/YSRealmStore/*.{h,m}",
    "requires_arc": true,
    "compiler_flags": "-fmodules",
    "dependencies": {
        "Realm": [
            "0.98.8"
        ]
    },
    "subspecs": [
        {
            "name": "Category",
            "source_files": "Classes/YSRealmStore/Category/*.{h,m}"
        }
    ]
}

Pin It on Pinterest

Share This