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

Background Realm Version License

Platforms
Swift support
CocoaPods Compatible
Carthage compatible
Twitter

Background Realm

Background Realm is a collection of handy classes and extensions that make it easier to work with RealmSwift in the background.

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

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

Specs

  • RealmSwift 3.0.0+
  • iOS 9+
  • tvOS 10+
  • watchOS 3+
  • macOS 10.10+
  • Swift 4.0+

Objective-C

For the Objective-C counterpart, see BLBackgroundRealm.

Writing to a Realm in the background

Commiting write transactions in the background becomes as easy as:

Realm.writeInBackground(configuration: <#T##Realm.Configuration?#>) { (realm, error) in
    <#code#>
}

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

Realm.Configuration.backgroundConfiguration = <#T##Realm.Configuration?#>

Realm.writeInBackground { (realm, error) in
    <#code#>
}

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

let realm = try Realm()

realm.writeInBackground { (backgroundRealm, error) in 
    <#code#>
}

The BackgroundRealm

Background Realm exposes a BackgroundRealm class, which basically:

  1. creates a private Thread and RunLoop where a new background Realm will be opened
  2. opens a Realm 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 Realm
  • register for change notifications in the background, without necessarily triggering a UI update right away

Usage

  • Creating a BackgroundRealm using Realm.Configuration.backgroundConfiguration:
let backgroundRealm = BackgroundRealm { (realm, error) in
    <#code#>
}
  • Creating a BackgroundRealm using a custom configuration:
let backgroundRealm = BackgroundRealm(configuration: <#T##Realm.Configuration?#>) { (realm, error) in
    <#code#>
}
  • Creating a BackgroundRealm using a file URL:
let backgroundRealm = BackgroundRealm(fileURL: <#T##URL#>) { (realm, error) in
    <#code#>
}

Installation

Cocoapods

pod 'BackgroundRealm', '~> 1.0'

Then import BackgroundRealm where needed.

Carthage

github "BellAppLab/BackgroundRealm" ~> 1.0

Then import BackgroundRealm where needed.

Git Submodules

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

Then drag the BackgroundRealm folder into your Xcode 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": "BackgroundRealm",
    "version": "1.0.5",
    "summary": "A collection of handy classes and extensions that make it easier to work with `RealmSwift` in the background.",
    "screenshots": "https://github.com/BellAppLab/BackgroundRealm/raw/master/Images/background_realm.png",
    "description": "Background Realm is a collection of handy classes and extensions that make it easier to work with `RealmSwift` 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 Objective-C counterpart, see [BLBackgroundRealm](https://github.com/BellAppLab/BLBackgroundRealm).",
    "homepage": "https://github.com/BellAppLab/BackgroundRealm",
    "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": "BackgroundRealm",
    "source": {
        "git": "https://github.com/BellAppLab/BackgroundRealm.git",
        "tag": "1.0.5"
    },
    "source_files": "BackgroundRealm",
    "frameworks": "Foundation",
    "dependencies": {
        "Realm": [
            "~> 3.0"
        ],
        "RealmSwift": [
            "~> 3.0"
        ]
    }
}

Pin It on Pinterest

Share This