Latest 1.0.5
Homepage https://github.com/BellAppLab/BLBackgroundRealm
License MIT
Platforms ios 9.0, osx 10.10, tvos 10.0, watchos 3.0
Dependencies Realm
Frameworks Foundation
Authors

BLBackgroundRealm Version License

Platforms
CocoaPods Compatible
Carthage compatible
Twitter

BLBackgroundRealm

BLBackgroundRealm is a collection of handy classes and extensions that make it easier to work with RLMRealm in the background.

It’s main focus is to enhance existing RLMRealms and Realm-based code bases with very little overhead and refactoring.

Note: Although this module makes it more convenient to work with a RLMRealm in the background, it does not make RLMRealms nor its objects thread-safe. They should still be accessed only from within their appropriate thread.

Specs

  • Realm 3.0.0+
  • iOS 9+
  • tvOS 10+
  • watchOS 3+
  • macOS 10.10+

Swift

For the Swift counterpart, see BackgroundRealm.

Writing to a Realm in the background

Commiting write transactions in the background becomes as easy as:

[RLMRealm writeInBackgroundWithConfiguration:<#(nonnull RLMRealmConfiguration *)#>
                                    andBlock:^(RLMRealm * _Nullable realm, BLBackgroundRealmError * _Nullable error) 
{
    <#code#>
}];

Optionally, you can set a default backgroundConfiguration that will be used in all write transactions in the background:

RLMRealmConfiguration *config = [[RLMRealmConfiguration alloc] init];
config.fileURL = url;
[RLMRealmConfiguration setBackgroundConfiguration:config];

[RLMRealm writeInBackgroundWithBlock:^(RLMRealm * _Nullable realm, BLBackgroundRealmError * _Nullable error) {
    <#code#>
}];

Finally, you can easily move from any Realm instance to its background counterpart:

RLMRealm *realm = [RLMRealm defaultRealm];

[realm writeInBackgroundWithBlock:^(RLMRealm * _Nullable realm, BLBackgroundRealmError * _Nullable error) {
    <#code#>
}];

The BackgroundRealm

Background Realm exposes a BLBackgroundRealm class, which basically:

  1. creates a private NSThread and NSRunLoop where a new background RLMRealm will be opened
  2. opens a RLMRealm in the private thread
  3. runs work in the background thread

This is particularly useful if you’d like to:

  • make computationally expensive changes to the RLMRealm
  • register for change notifications in the background, without necessarily triggering a UI update right away

Usage

  • Creating a BLBackgroundRealm using [RLMConfiguration backgroundConfiguration]:
BLBackgroundRealm *bgRealm = [BLBackgroundRealm backgroundRealmWithBlock:^(RLMRealm * _Nullable realm, BLBackgroundRealmError * _Nullable error) {
    <#code#>
}];
  • Creating a BLBackgroundRealm using a custom configuration:
[BLBackgroundRealm backgroundRealmWithConfiguration:<#(nonnull RLMRealmConfiguration *)#> 
                                           andBlock:^(RLMRealm * _Nullable realm, BLBackgroundRealmError * _Nullable error) 
{
    <#code#>
}];
  • Creating a BLBackgroundRealm using a file NSURL:
[BLBackgroundRealm backgroundRealmWithFileURL:<#(nonnull NSURL *)#> 
                                     andBlock:^(RLMRealm * _Nullable realm, BLBackgroundRealmError * _Nullable error) 
{
    <#code#>
}];

Installation

Cocoapods

pod 'BLBackgroundRealm', '~> 1.0'

Then #import <BLBackgroundRealm/BLBackgroundRealm.h> where needed.

Carthage

github "BellAppLab/BLBackgroundRealm" ~> 1.0

Then #import <BLBackgroundRealm/BLBackgroundRealm.h> where needed.

Git Submodules

cd toYourProjectsFolder
git submodule add -b submodule --name BLBackgroundRealm https://github.com/BellAppLab/BLBackgroundRealm.git

Then drag the BLBackgroundRealm folder into your Xcode project.

Forks

When forking this repo, make sure to download the Realm framework and add it manually to the project.

Author

Bell App Lab, [email protected]

Contributing

Check this out.

Credits

Logo image by mikicon from The Noun Project

License

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

Latest podspec

{
    "name": "BLBackgroundRealm",
    "version": "1.0.5",
    "summary": "A collection of handy classes and extensions that make it easier to work with `Realm` in the background.",
    "screenshots": "https://github.com/BellAppLab/BLBackgroundRealm/raw/master/Images/background_realm.png",
    "description": "BLBackgroundRealm is a collection of handy classes and extensions that make it easier to work with `Realm` in the background.nnIt's main focus is to enhance existing `Realm`s and Realm-based code bases with very little overhead and refactoring.nn**Note**: Although this module makes it more convenient to work with a `Realm` in the background, it does **not** make  `Realm`s nor its objects thread-safe. They should still be accessed only from within their appropriate thread.nnFor the Swift counterpart, see [BackgroundRealm](https://github.com/BellAppLab/BackgroundRealm).",
    "homepage": "https://github.com/BellAppLab/BLBackgroundRealm",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Bell App Lab": "[email protected]"
    },
    "social_media_url": "https://twitter.com/BellAppLab",
    "platforms": {
        "ios": "9.0",
        "osx": "10.10",
        "tvos": "10.0",
        "watchos": "3.0"
    },
    "module_name": "BLBackgroundRealm",
    "header_dir": "Headers",
    "source": {
        "git": "https://github.com/BellAppLab/BLBackgroundRealm.git",
        "tag": "1.0.5"
    },
    "source_files": [
        "BLBackgroundRealm",
        "Headers"
    ],
    "frameworks": "Foundation",
    "dependencies": {
        "Realm": [
            "~> 3.0"
        ]
    }
}

Pin It on Pinterest

Share This