{"id":19252226,"url":"https://github.com/bellapplab/backgroundrealm","last_synced_at":"2025-07-14T09:40:25.015Z","repository":{"id":54256046,"uuid":"138168843","full_name":"BellAppLab/BackgroundRealm","owner":"BellAppLab","description":"A collection of handy classes and extensions that make it easier to work with RealmSwift in the background.","archived":false,"fork":false,"pushed_at":"2023-02-08T16:59:24.000Z","size":818,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-13T17:19:30.460Z","etag":null,"topics":["ios","macos","osx","realm","realmswift","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BellAppLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-21T12:42:33.000Z","updated_at":"2024-03-23T13:57:37.000Z","dependencies_parsed_at":"2024-11-09T18:27:22.745Z","dependency_job_id":"a3b4a465-9bc4-47d3-ba2d-234c4b350e98","html_url":"https://github.com/BellAppLab/BackgroundRealm","commit_stats":{"total_commits":48,"total_committers":3,"mean_commits":16.0,"dds":"0.27083333333333337","last_synced_commit":"9c4629b6cb3ef3e2e5778253b926945bcd80b2e1"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FBackgroundRealm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FBackgroundRealm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FBackgroundRealm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FBackgroundRealm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BellAppLab","download_url":"https://codeload.github.com/BellAppLab/BackgroundRealm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250064528,"owners_count":21368922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","osx","realm","realmswift","swift","tvos","watchos"],"created_at":"2024-11-09T18:26:03.289Z","updated_at":"2025-04-21T13:30:44.298Z","avatar_url":"https://github.com/BellAppLab.png","language":"Swift","readme":"# Background Realm [![Version](https://img.shields.io/badge/Version-4.0.0-black.svg?style=flat)](#installation) [![License](https://img.shields.io/cocoapods/l/BackgroundRealm.svg?style=flat)](#license)\n\n[![Platforms](https://img.shields.io/badge/Platforms-iOS|tvOS|macOS|watchOS-brightgreen.svg?style=flat)](#installation)\n[![Swift support](https://img.shields.io/badge/Swift-5.3%20%7C%205.7-red.svg?style=flat)](#swift-versions-support)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/BackgroundRealm.svg?style=flat\u0026label=CocoaPods)](https://cocoapods.org/pods/BackgroundRealm)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-red.svg?style=flat)](https://github.com/apple/swift-package-manager)\n[![Twitter](https://img.shields.io/badge/Twitter-@BellAppLab-blue.svg?style=flat)](http://twitter.com/BellAppLab)\n\n![Background Realm](./Images/background_realm.png)\n\nBackground Realm is a collection of handy classes and extensions that make it easier to work with `RealmSwift` in the background.\n\nIt's main focus is to enhance existing `Realm`s and Realm-based code bases with very little overhead and refactoring. \n\n**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.\n\n## Specs\n\n* RealmSwift 10.0.0+\n* iOS 12+\n* tvOS 12+\n* watchOS 4+\n* macOS 10.13+\n* Swift 5.0+\n\n### Objective-C\n\nFor the Objective-C counterpart, see [BLBackgroundRealm](https://github.com/BellAppLab/BLBackgroundRealm).\n\n## Writing to a Realm in the background\n\nPerforming write transactions in the background becomes as easy as:\n\n```swift\nRealm.writeInBackground(configuration: \u003c#T##Realm.Configuration?#\u003e) { (result) in\n    \u003c#code#\u003e\n}\n```\n\nOptionally, you can set a default `backgroundConfiguration` that will be used in all write transactions in the background:\n\n```swift\nRealm.Configuration.backgroundConfiguration = \u003c#T##Realm.Configuration?#\u003e\n\nRealm.writeInBackground { (result) in\n    \u003c#code#\u003e\n}\n```\n\nFinally, you can easily move from any `Realm` instance to its background counterpart:\n\n```swift\nlet realm = try Realm()\n\nrealm.writeInBackground { (result) in \n    \u003c#code#\u003e\n}\n```\n\n## Commiting to a Realm in the background\n\nSimilarly to write operations, you can commit transactinos to a `Realm` in the background. The difference being that commits can be cancelled:\n\n```swift\nRealm.commitInBackground(configuration: \u003c#T##Realm.Configuration?#\u003e) { (result) -\u003e Bool in\n    \u003c#code#\u003e\n    return false //return true if you want to cancel this write operation\n}\n```\n\nYou can also move from any `Realm` instance to its background counterpart:\n\n```swift\nlet realm = try Realm()\n\nrealm.commitInBackground { (result) -\u003e Bool in \n    \u003c#code#\u003e\n    return false //return true if you want to cancel this write operation\n}\n```\n\n## The `BackgroundRealm`\n\nBackground Realm exposes a `BackgroundRealm`  class, which basically:\n\n1. creates a private `Thread` and `RunLoop` where a new background `Realm` will be opened\n2. opens a `Realm` in the private thread\n3. runs work in the background thread\n\nThis is particularly useful if you'd like to:\n\n- make computationally expensive changes to the `Realm`\n- register for change notifications in the background, without necessarily triggering a UI update right away\n\n### Usage\n\n- Creating a `BackgroundRealm` using `Realm.Configuration.backgroundConfiguration`:\n\n```swift\nlet backgroundRealm = BackgroundRealm { (result) in\n    \u003c#code#\u003e\n}\n```\n\n- Creating a `BackgroundRealm` using a custom configuration:\n\n```swift\nlet backgroundRealm = BackgroundRealm(configuration: \u003c#T##Realm.Configuration?#\u003e) { (result) in\n    \u003c#code#\u003e\n}\n```\n\n- Creating a `BackgroundRealm` using a file `URL`:\n\n```swift\nlet backgroundRealm = BackgroundRealm(fileURL: \u003c#T##URL#\u003e) { (result) in\n    \u003c#code#\u003e\n}\n```\n\n## Queues\n\n`BackgroundRealm` uses two queues to process things in the background: \n\n- `DispatchQueue.backgroundRealm`\n- `OperationQueue.backgroundRealm`\n\nIf you'd like to use your own queues, just set those as early as possible in you app's life cycle.\n\n## Installation\n\n### Cocoapods\n\n```ruby\npod 'BackgroundRealm', '~\u003e 4.0'\n```\n\nThen `import BackgroundRealm` where needed.\n\n### Carthage\n\n```swift\ngithub \"BellAppLab/BackgroundRealm\" ~\u003e 4.0\n```\n\nThen `import BackgroundRealm` where needed.\n\n### Swift Package Manager\n\n```swift\n.package(url: \"https://github.com/BellAppLab/BackgroundRealm.git\", from: \"4.0.0\")\n```\n\n### Git Submodules\n\n```shell\ncd toYourProjectsFolder\ngit submodule add -b submodule --name BackgroundRealm https://github.com/BellAppLab/BackgroundRealm.git\n```\n\nThen drag the `BackgroundRealm` folder into your Xcode project.\n\n## Author\n\nBell App Lab, apps@bellapplab.com\n\n### Contributing\n\nCheck [this out](./CONTRIBUTING.md).\n\n### Credits\n\n[Logo image](https://thenounproject.com/search/?q=background\u0026i=635453#) by [mikicon](https://thenounproject.com/mikicon) from [The Noun Project](https://thenounproject.com/)\n\n## License\n\nBackgroundRealm is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Fbackgroundrealm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbellapplab%2Fbackgroundrealm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Fbackgroundrealm/lists"}