{"id":1809,"url":"https://github.com/RxSwiftCommunity/RxRealm","last_synced_at":"2025-08-02T04:32:37.327Z","repository":{"id":7843249,"uuid":"56589037","full_name":"RxSwiftCommunity/RxRealm","owner":"RxSwiftCommunity","description":"RxSwift extension for RealmSwift's types","archived":false,"fork":false,"pushed_at":"2025-07-29T02:48:51.000Z","size":21731,"stargazers_count":1166,"open_issues_count":14,"forks_count":274,"subscribers_count":38,"default_branch":"main","last_synced_at":"2025-07-30T19:24:58.733Z","etag":null,"topics":["database","reactive","realm","realmswift","rxswift"],"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/RxSwiftCommunity.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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,"zenodo":null}},"created_at":"2016-04-19T10:53:02.000Z","updated_at":"2025-07-29T02:48:56.000Z","dependencies_parsed_at":"2023-02-14T04:16:31.887Z","dependency_job_id":"c043da73-6286-4f01-9c2f-742be14ba697","html_url":"https://github.com/RxSwiftCommunity/RxRealm","commit_stats":{"total_commits":197,"total_committers":41,"mean_commits":4.804878048780488,"dds":0.4517766497461929,"last_synced_commit":"5431fe18e341c41b9eeb56cf68e709ba8e54d4c9"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"purl":"pkg:github/RxSwiftCommunity/RxRealm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxRealm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxRealm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxRealm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxRealm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RxSwiftCommunity","download_url":"https://codeload.github.com/RxSwiftCommunity/RxRealm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxRealm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267936473,"owners_count":24168550,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","reactive","realm","realmswift","rxswift"],"created_at":"2024-01-05T20:15:56.320Z","updated_at":"2025-08-02T04:32:36.747Z","avatar_url":"https://github.com/RxSwiftCommunity.png","language":"Swift","funding_links":[],"categories":["Swift","Reactive Programming","Libraries","Major"],"sub_categories":["\u003ca name=\"swift-libs\"\u003e\u003c/a\u003eSwift Libraries and Components","Other free courses","Prototyping","Other Parsing","Concurrency"],"readme":"# RxRealm\n\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Version](https://img.shields.io/cocoapods/v/RxRealm.svg?style=flat)](http://cocoapods.org/pods/RxRealm)\n[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![License](https://img.shields.io/cocoapods/l/RxRealm.svg?style=flat)](http://cocoapods.org/pods/RxRealm)\n[![Platform](https://img.shields.io/cocoapods/p/RxRealm.svg?style=flat)](http://cocoapods.org/pods/RxRealm)\n\nThis library is a thin wrapper around __RealmSwift__ ( [Realm Docs](https://realm.io/docs/swift/latest/) ).\n\n**Table of contents:**\n\n 1. [Observing object collections](https://github.com/RxSwiftCommunity/RxRealm#observing-object-collections)\n 2. [Observing a single object](https://github.com/RxSwiftCommunity/RxRealm#observing-a-single-object)\n 3. [Write transactions](https://github.com/RxSwiftCommunity/RxRealm#write-transactions)\n 4. [Automatically binding table and collection views](https://github.com/RxSwiftCommunity/RxRealm#automatically-binding-table-and-collection-views)\n 5. [Example app](https://github.com/RxSwiftCommunity/RxRealm#example-app)\n\n## Observing object collections\n\nRxRealm can be used to create `Observable`s from objects of type `Results`, `List`, `LinkingObjects` or `AnyRealmCollection`. These types are typically used to load and observe object collections from the Realm Mobile Database.\n\n##### `Observable.collection(from:synchronousStart:)`\nEmits an event each time the collection changes:\n\n```swift\nlet realm = try! Realm()\nlet laps = realm.objects(Lap.self)\n\nObservable.collection(from: laps)\n  .map { \n    laps in \"\\(laps.count) laps\"\n  }\n  .subscribe(onNext: { text  in\n    print(text)\n  })\n```\n\nThe above prints out \"X laps\" each time a lap is added or removed from the database. If you set `synchronousStart` to `true` (the default value), the first element will be emitted synchronously - e.g. when you're binding UI it might not be possible for an asynchronous notification to come through.\n\n##### `Observable.array(from:synchronousStart:)`\nUpon each change fetches a snapshot of the Realm collection and converts it to an array value (for example if you want to use array methods on the collection):\n\n```swift\nlet realm = try! Realm()\nlet laps = realm.objects(Lap.self)\n\nObservable.array(from: laps)\n  .map { array in\n    return array.prefix(3) //slice of first 3 items\n  }\n  .subscribe(onNext: { text  in\n    print(text)\n  })\n```\n\n##### `Observable.changeset(from:synchronousStart:)`\nEmits every time the collection changes and provides the exact indexes that has been deleted, inserted or updated:\n\n```swift\nlet realm = try! Realm()\nlet laps = realm.objects(Lap.self)\n\nObservable.changeset(from: laps)\n  .subscribe(onNext: { results, changes in\n    if let changes = changes {\n      // it's an update\n      print(results)\n      print(\"deleted: \\(changes.deleted)\")\n      print(\"inserted: \\(changes.inserted)\")\n      print(\"updated: \\(changes.updated)\")\n    } else {\n      // it's the initial data\n      print(results)\n    }\n  })\n```\n\n##### `Observable.arrayWithChangeset(from:synchronousStart:)`\nCombines the result of `Observable.array(from:)` and `Observable.changeset(from:)` returning an `Observable\u003cArray\u003cT\u003e, RealmChangeset?\u003e`\n\n```swift\nlet realm = try! Realm()\nlet laps = realm.objects(Lap.self))\n\nObservable.arrayWithChangeset(from: laps)\n  .subscribe(onNext: { array, changes in\n    if let changes = changes {\n    // it's an update\n    print(array.first)\n    print(\"deleted: \\(changes.deleted)\")\n    print(\"inserted: \\(changes.inserted)\")\n    print(\"updated: \\(changes.updated)\")\n  } else {\n    // it's the initial data\n    print(array)\n  }\n  })\n```\n\n## Observing a single object\n\nThere's a separate API to make it easier to observe a single object:\n\n```swift\nObservable.from(object: ticker)\n    .map { ticker -\u003e String in\n        return \"\\(ticker.ticks) ticks\"\n    }\n    .bindTo(footer.rx.text)\n```\n\nThis API uses the [Realm object notifications](https://realm.io/news/realm-objc-swift-2.4/) under the hood to listen for changes.\n\nThis method will by default emit the object initial state as its first `next` event. You can disable this behavior by using the `emitInitialValue` parameter and setting it to `false`.\n\nFinally you can set changes to which properties constitute an object change you'd like to observe for:\n\n```swift\nObservable.from(object: ticker, properties: [\"name\", \"id\", \"family\"]) ...\n```\n\n## Write transactions\n\n##### `rx.add()`\n\nWriting objects to **existing** realm reference. You can add newly created objects to a Realm that you already have initialized:\n\n```swift\nlet realm = try! Realm()\nlet messages = [Message(\"hello\"), Message(\"world\")]\n\nObservable.from(messages)\n  .subscribe(realm.rx.add())\n```\n\nBe careful, this will retain your Realm until the `Observable` completes or errors out.\n\n##### `Realm.rx.add()`\n\nWriting to the default Realm. You can leave it to RxRealm to grab the default Realm on any thread your subscribe and write objects to it:\n\n```swift\nlet messages = [Message(\"hello\"), Message(\"world\")]\n\nObservable.from(messages)\n  .subscribe(Realm.rx.add())\n```\n\n###### `Realm.rx.add(configuration:)`\n\nWriting to a **custom** Realm. If you want to switch threads and not use the default Realm, provide a `Realm.Configuration`. You an also provide an error handler for the observer to be called if either creating the realm reference or the write transaction raise an error:\n\n```swift\nvar config = Realm.Configuration()\n/* custom configuration settings */\n\nlet messages = [Message(\"hello\"), Message(\"world\")]\nObservable.from(messages)\n  .observeOn( /* you can switch threads here */ )     \n  .subscribe(Realm.rx.add(configuration: config, onError: {elements, error in\n    if let elements = elements {\n      print(\"Error \\(error.localizedDescription) while saving objects \\(String(describing: elements))\")\n    } else {\n      print(\"Error \\(error.localizedDescription) while opening realm.\")\n    }\n  }))\n```\n\nIf you want to create a Realm on a different thread manually, allowing you to handle errors, you can do that too:\n\n```swift\nlet messages = [Message(\"hello\"), Message(\"world\")]\n\nObservable.from(messages)\n  .observeOn( /* you can switch threads here */ )\n  .subscribe(onNext: {messages in\n    let realm = try! Realm()\n    try! realm.write {\n      realm.add(messages)\n    }\n  })\n```\n\n##### `rx.delete()`\n\nDeleting object(s) from an existing realm reference:\n\n```swift\nlet realm = try! Realm()\nlet messages = realm.objects(Message.self)\nObservable.from(messages)\n  .subscribe(realm.rx.delete())\n```\n\nBe careful, this will retain your realm until the `Observable` completes or errors out.\n\n##### `Realm.rx.delete()`\n\nDeleting from the object's realm automatically. You can leave it to RxRealm to grab the Realm from the first object and use it:\n\n```swift\nObservable.from(someCollectionOfPersistedObjects)\n  .subscribe(Realm.rx.delete())\n```\n\n## Automatically binding table and collection views\n\nRxRealm does not depend on UIKit/Cocoa and it doesn't provide built-in way to bind Realm collections to UI components.\n\n#### a) Non-animated binding\n\nYou can use the built-in RxCocoa `bindTo(_:)` method, which will automatically drive your table view from your Realm results:\n\n```swift\nObservable.from( [Realm collection] )\n  .bindTo(tableView.rx.items) {tv, ip, element in\n    let cell = tv.dequeueReusableCell(withIdentifier: \"Cell\")!\n    cell.textLabel?.text = element.text\n    return cell\n  }\n  .addDisposableTo(bag)\n```\n\n#### b) Animated binding with RxRealmDataSources\n\nThe separate library [RxRealmDataSources](https://github.com/RxSwiftCommunity/RxRealmDataSources) mimics the default data sources library behavior for RxSwift.\n\n`RxRealmDataSources` allows you to bind an observable collection of Realm objects directly to a table or collection view:\n\n```swift\n// create data source\nlet dataSource = RxTableViewRealmDataSource\u003cLap\u003e(\n  cellIdentifier: \"Cell\", cellType: PersonCell.self) {cell, ip, lap in\n    cell.customLabel.text = \"\\(ip.row). \\(lap.text)\"\n}\n\n// RxRealm to get Observable\u003cResults\u003e\nlet realm = try! Realm()\nlet lapsList = realm.objects(Timer.self).first!.laps\nlet laps = Observable.changeset(from: lapsList)\n\n// bind to table view\nlaps\n  .bindTo(tableView.rx.realmChanges(dataSource))\n  .addDisposableTo(bag)\n```\n\nThe data source will reflect all changes via animations to the table view:\n\n![RxRealm animated changes](assets/animatedChanges.gif)\n\nIf you want to learn more about the features beyond animating changes, check the __`RxRealmDataSources`__ [README](https://github.com/RxSwiftCommunity/RxRealmDataSources).\n\n## Example app\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first. The app uses RxSwift, RxCocoa using RealmSwift, RxRealm to observe Results from Realm.\n\nFurther you're welcome to peak into the __RxRealmTests__ folder of the example app, which features the library's unit tests.\n\n## Installation\n\nThis library depends on both __RxSwift__ and __RealmSwift__ 1.0+.\n\n#### CocoaPods\n\nRxRealm requires CocoaPods 1.1.x or higher.\n\nRxRealm is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:\n\n```ruby\npod \"RxRealm\"\n```\n\n#### Carthage\n\nTo integrate RxRealm into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"RxSwiftCommunity/RxRealm\"\n```\n\nRun `carthage update` to build the framework and drag the built `RxRealm.framework` into your Xcode project.\n\n#### Swift Package Manager\n\nIn your Package.swift:\n\n```swift\nlet package = Package(\n  name: \"Example\",\n  dependencies: [\n    .package(url: \"https://github.com/RxSwiftCommunity/RxRealm.git\", from: \"1.0.1\")\n  ],\n  targets: [\n    .target(name: \"Example\", dependencies: [\"RxRealm\"])\n  ]\n)\n```\n\n## TODO\n\n* Test add platforms and add compatibility for the pod\n\n## License\n\nThis library belongs to _RxSwiftCommunity_. Maintainer is [Marin Todorov](https://github.com/icanzilb).\n\nRxRealm is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRxSwiftCommunity%2FRxRealm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRxSwiftCommunity%2FRxRealm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRxSwiftCommunity%2FRxRealm/lists"}