{"id":13475121,"url":"https://github.com/RxSwiftCommunity/RxDataSources","last_synced_at":"2025-03-26T23:30:30.321Z","repository":{"id":37445028,"uuid":"48885353","full_name":"RxSwiftCommunity/RxDataSources","owner":"RxSwiftCommunity","description":"UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)","archived":false,"fork":false,"pushed_at":"2024-07-10T15:57:11.000Z","size":2108,"stargazers_count":3093,"open_issues_count":85,"forks_count":494,"subscribers_count":67,"default_branch":"main","last_synced_at":"2024-10-29T15:34:09.254Z","etag":null,"topics":["animation","binding","collectionview","datasource","diff","rxswift","sections","tableview","unidirectional"],"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.md","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":"2016-01-01T18:03:22.000Z","updated_at":"2024-10-24T13:56:19.000Z","dependencies_parsed_at":"2024-01-16T07:23:36.965Z","dependency_job_id":"128c4986-345a-46b7-931b-7aa3f1d084bc","html_url":"https://github.com/RxSwiftCommunity/RxDataSources","commit_stats":{"total_commits":347,"total_committers":55,"mean_commits":"6.3090909090909095","dds":0.4005763688760807,"last_synced_commit":"bbfea3869f5492580563c676acda729c64fa489e"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxDataSources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxDataSources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxDataSources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RxSwiftCommunity%2FRxDataSources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RxSwiftCommunity","download_url":"https://codeload.github.com/RxSwiftCommunity/RxDataSources/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245191486,"owners_count":20575246,"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":["animation","binding","collectionview","datasource","diff","rxswift","sections","tableview","unidirectional"],"created_at":"2024-07-31T16:01:17.532Z","updated_at":"2025-03-26T23:30:30.283Z","avatar_url":"https://github.com/RxSwiftCommunity.png","language":"Swift","readme":"[![Travis CI](https://travis-ci.org/RxSwiftCommunity/RxDataSources.svg?branch=main)](https://travis-ci.org/RxSwiftCommunity/RxDataSources)\n\nTable and Collection view data sources\n======================================\n\n## Features\n\n- [x] **O(N)** algorithm for calculating differences\n  - the algorithm has the assumption that all sections and items are unique so there is no ambiguity\n  - in case there is ambiguity, fallbacks automagically on non animated refresh\n- [x] it applies additional heuristics to send the least number of commands to sectioned view\n  - even though the running time is linear, preferred number of sent commands is usually a lot less than linear\n  - it is preferred (and possible) to cap the number of changes to some small number, and in case the number of changes grows towards linear, just do normal reload\n- [x] Supports **extending your item and section structures**\n  - just extend your item with `IdentifiableType` and `Equatable`, and your section with `AnimatableSectionModelType`\n- [x] Supports all combinations of two level hierarchical animations for **both sections and items**\n  - Section animations: Insert, Delete, Move\n  - Item animations: Insert, Delete, Move, Reload (if old value is not equal to new value)\n- [x] Configurable animation types for `Insert`, `Reload` and `Delete` (Automatic, Fade, ...)\n- [x] Example app\n- [x] Randomized stress tests (example app)\n- [x] Supports editing out of the box (example app)\n- [x] Works with `UITableView` and `UICollectionView`\n\n## Why\nWriting table and collection view data sources is tedious. There is a large number of delegate methods that need to be implemented for the simplest case possible.\n\nRxSwift helps alleviate some of the burden with a simple data binding mechanism:\n1) Turn your data into an Observable sequence\n2) Bind the data to the tableView/collectionView using one of:\n  - `rx.items(dataSource:protocol\u003cRxTableViewDataSourceType, UITableViewDataSource\u003e)`\n  - `rx.items(cellIdentifier:String)`\n  - `rx.items(cellIdentifier:String:Cell.Type:_:)`\n  - `rx.items(_:_:)`\n\n```swift\nlet data = Observable\u003c[String]\u003e.just([\"first element\", \"second element\", \"third element\"])\n\ndata.bind(to: tableView.rx.items(cellIdentifier: \"Cell\")) { index, model, cell in\n  cell.textLabel?.text = model\n}\n.disposed(by: disposeBag)\n```\n\nThis works well with simple data sets but does not handle cases where you need to bind complex data sets with multiples sections, or when you need to perform animations when adding/modifying/deleting items.  \n\nThese are precisely the use cases that RxDataSources helps solve.\n\nWith RxDataSources, it is super easy to just write\n\n```swift\nlet dataSource = RxTableViewSectionedReloadDataSource\u003cSectionModel\u003cString, Int\u003e\u003e(configureCell: configureCell)\nObservable.just([SectionModel(model: \"title\", items: [1, 2, 3])])\n    .bind(to: tableView.rx.items(dataSource: dataSource))\n    .disposed(by: disposeBag)\n```\n![RxDataSources example app](https://raw.githubusercontent.com/kzaher/rxswiftcontent/rxdatasources/RxDataSources.gif)\n\n## How\nGiven the following custom data structure:\n```swift\nstruct CustomData {\n  var anInt: Int\n  var aString: String\n  var aCGPoint: CGPoint\n}\n```\n\n1) Start by defining your sections with a struct that conforms to the `SectionModelType` protocol:\n  - define the `Item` typealias: equal to the type of items that the section will contain\n  - declare an `items` property: of type array of `Item`\n\n```swift\nstruct SectionOfCustomData {\n  var header: String    \n  var items: [Item]\n}\nextension SectionOfCustomData: SectionModelType {\n  typealias Item = CustomData\n\n   init(original: SectionOfCustomData, items: [Item]) {\n    self = original\n    self.items = items\n  }\n}\n```\n\n2) Create a dataSource object and pass it your `SectionOfCustomData` type:\n```swift\nlet dataSource = RxTableViewSectionedReloadDataSource\u003cSectionOfCustomData\u003e(\n  configureCell: { dataSource, tableView, indexPath, item in\n    let cell = tableView.dequeueReusableCell(withIdentifier: \"Cell\", for: indexPath)\n    cell.textLabel?.text = \"Item \\(item.anInt): \\(item.aString) - \\(item.aCGPoint.x):\\(item.aCGPoint.y)\"\n    return cell\n})\n```\n\n3) Customize closures on the dataSource as needed:\n- `titleForHeaderInSection`\n- `titleForFooterInSection`\n- etc\n\n```swift\ndataSource.titleForHeaderInSection = { dataSource, index in\n  return dataSource.sectionModels[index].header\n}\n\ndataSource.titleForFooterInSection = { dataSource, index in\n  return dataSource.sectionModels[index].footer\n}\n\ndataSource.canEditRowAtIndexPath = { dataSource, indexPath in\n  return true\n}\n\ndataSource.canMoveRowAtIndexPath = { dataSource, indexPath in\n  return true\n}\n```\n\n4) Define the actual data as an Observable sequence of CustomData objects and bind it to the tableView\n```swift\nlet sections = [\n  SectionOfCustomData(header: \"First section\", items: [CustomData(anInt: 0, aString: \"zero\", aCGPoint: CGPoint.zero), CustomData(anInt: 1, aString: \"one\", aCGPoint: CGPoint(x: 1, y: 1)) ]),\n  SectionOfCustomData(header: \"Second section\", items: [CustomData(anInt: 2, aString: \"two\", aCGPoint: CGPoint(x: 2, y: 2)), CustomData(anInt: 3, aString: \"three\", aCGPoint: CGPoint(x: 3, y: 3)) ])\n]\n\nObservable.just(sections)\n  .bind(to: tableView.rx.items(dataSource: dataSource))\n  .disposed(by: disposeBag)\n```\n\n### Animated Data Sources\n\nRxDataSources provides two special data source types that automatically take care of animating changes in the bound data source: `RxTableViewSectionedAnimatedDataSource` and `RxCollectionViewSectionedAnimatedDataSource`.\n\nTo use one of the two animated data sources, you must take a few extra steps on top of those outlined above:\n\n- SectionOfCustomData needs to conform to `AnimatableSectionModelType`\n- Your data model must conform to\n  * `IdentifiableType`: The `identity` provided by the `IdentifiableType` protocol must be an **immutable identifier representing an instance of the model**. For example, in case of a `Car` model, you might want to use the car's `plateNumber` as its identity.\n  * `Equatable`: Conforming to `Equatable` helps `RxDataSources` determine which cells have changed so it can animate only these specific cells. Meaning, changing **any** of the `Car` model's properties will trigger an animated reload of that cell.\n\n## Requirements\n\nXcode 10.2\n\nSwift 5.0\n\nFor Swift 4.x version please use versions `3.0.0 ... 3.1.0`\nFor Swift 3.x version please use versions `1.0 ... 2.0.2`\nFor Swift 2.3 version please use versions `0.1 ... 0.9`\n\n## Installation\n\n**We'll try to keep the API as stable as possible, but breaking API changes can occur.**\n\n### CocoaPods\n\nPodfile\n```\npod 'RxDataSources', '~\u003e 5.0'\n```\n\n### Carthage\n\nCartfile\n```\ngithub \"RxSwiftCommunity/RxDataSources\" ~\u003e 5.0\n```\n\n### Swift Package Manager\n\nCreate a `Package.swift` file.\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"SampleProject\",\n    dependencies: [\n        .package(url: \"https://github.com/RxSwiftCommunity/RxDataSources.git\", from: \"5.0.0\")\n    ]\n)\n```\n\nIf you are using Xcode 11 or higher, go to **File / Swift Packages / Add Package Dependency...** and enter package repository URL **https://github.com/RxSwiftCommunity/RxDataSources.git**, then follow the instructions.\n","funding_links":[],"categories":["Swift","Libraries","OOM-Leaks-Crash","Major"],"sub_categories":["Rx Series","Concurrency"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRxSwiftCommunity%2FRxDataSources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRxSwiftCommunity%2FRxDataSources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRxSwiftCommunity%2FRxDataSources/lists"}