{"id":16426412,"url":"https://github.com/cgossain/firebaseresultscontroller","last_synced_at":"2026-05-16T06:10:40.787Z","repository":{"id":56911298,"uuid":"82240706","full_name":"cgossain/FirebaseResultsController","owner":"cgossain","description":"An NSFetchedResultsController replacement for FirebaseDatabase on iOS, written in Swift.","archived":false,"fork":false,"pushed_at":"2021-04-06T18:09:42.000Z","size":139782,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-15T10:21:34.292Z","etag":null,"topics":["batch-processing","diff","diffing","diffing-data","firebase","firebase-realtime-database","realtime-updates","uitableview"],"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/cgossain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-17T00:45:38.000Z","updated_at":"2023-07-01T02:53:05.000Z","dependencies_parsed_at":"2022-08-21T04:20:39.357Z","dependency_job_id":null,"html_url":"https://github.com/cgossain/FirebaseResultsController","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2FFirebaseResultsController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2FFirebaseResultsController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2FFirebaseResultsController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgossain%2FFirebaseResultsController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cgossain","download_url":"https://codeload.github.com/cgossain/FirebaseResultsController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240594175,"owners_count":19826117,"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":["batch-processing","diff","diffing","diffing-data","firebase","firebase-realtime-database","realtime-updates","uitableview"],"created_at":"2024-10-11T08:09:09.868Z","updated_at":"2026-05-16T06:10:40.741Z","avatar_url":"https://github.com/cgossain.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FirebaseResultsController\n[![CI Status](http://img.shields.io/travis/cgossain@gmail.com/FirebaseResultsController.svg?style=flat)](https://travis-ci.org/cgossain@gmail.com/FirebaseResultsController)\n[![Version](https://img.shields.io/cocoapods/v/FirebaseResultsController.svg?style=flat)](http://cocoapods.org/pods/FirebaseResultsController)\n[![License](https://img.shields.io/cocoapods/l/FirebaseResultsController.svg?style=flat)](http://cocoapods.org/pods/FirebaseResultsController)\n[![Platform](https://img.shields.io/cocoapods/p/FirebaseResultsController.svg?style=flat)](http://cocoapods.org/pods/FirebaseResultsController)\n\nFirebaseResultsController is a controller used to manage the results of a query attached to a Firebase Realtime Database.\n\nIt offers additional filtering and sorting capabilities, diffing support (using LCS algoritm), and realtime content updates. These features come together to facilitate building data driven UITableView's.\n\n## Example\n\nThis project includes a simple demo application that demonstrates how to use a FirebaseResultsController to power an instance of UITableView.\n\n### Prerequisites\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\nYou'll also need to create a Firebase account, and follow the instructions to create a demo project. Once your demo project has been created in your Firebase account, you'll need to download the project's corresponding `GoogleService-Info.plist` and add it the demo project. The Firebase framework automatically detects this file when the app launches, and will configure the environment accordingly.\n\nP.S You can just copy your `GoogleService-Info.plist` directly to the `Example/FirebaseResultsController/` directory, and the Xcode project should automatically pick it up.\n\n## Installation\n\nFirebaseResultsController is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"FirebaseResultsController\"\n```\n\n## Usage Instructions\n\n### FirebaseFetchRequest\nTo describe a fetch operation, you need to first create a FirebaseFetchRequest. You create a FirebaseFetchRequest with a Firebase DatabaseQuery instance. A DatabaseQuery already provides support for filtering and sorting, but only to a certain extent. If the built in behaviour is not enough, you can specify an NSPredicate, and an array of NSSortDescriptor's that can be applied to the final fetched data.\n\n```\nlet query: DatabaseQuery = ...      // some Firebase query\n\nlet fetchRequest = FirebaseFetchRequest(query: query)\nfetchRequest.predicate = ...        // optional NSPredicate that is applied to fetched data\nfetchRequest.sortDescriptors = ...  // optional array of NSSortDescriptor's applied to fetched data\n```\n\n### FirebaseResultsController\nThe FirebaseResultsController is the main class used to fetch the data. You create it with a FirebaseFetchRequest, and optionally a `sectionNameKeyPath` on result objects that returns the section name.\n\n```\nlet controller = FirebaseResultsController(fetchRequest: fetchRequest, sectionNameKeyPath: \u003coptional key path\u003e)\n```\n\nYou must call `performFetch()` at least once to begin receiving data. Afterwards, if you change the predicate or sort descriptors on the controller's fetch request, you must call `performFetch()` again (i.e. filtering via a search bar).\n```\ncontroller.fetchRequest.predicate = ...         // updated predicate\ncontroller.fetchRequest.sortDescriptors = ...   // updated sort descriptors\n\ncontroller.performFetch()                       // reconfigures the controller for the updated fetch request\n```\n\nCalling `performFetch()` will attach observers for the specified database query. This automatically provides realtime updates to the controller's content. To enabled diffing these realtime updates, you need to specify a `changeTracker` which is an object that conforms to the `FirebaseResultsControllerChangeTracking` protocol.\n```\ncontroller.changeTracker = ... // object that conforms to FirebaseResultsControllerChangeTracking\n```\n\nFor Example:\n```\nextension ViewController: FirebaseResultsControllerChangeTracking {\n    func controller(_ controller: FirebaseResultsController, didChangeContentWith changes: FetchResultChanges) {\n        tableView.beginUpdates()\n\n        // apply section changes\n        changes.enumerateSectionChanges { (section, sectionIndex, type) in\n            switch type {\n            case .insert:\n                self.tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)\n            case .delete:\n                self.tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)\n            default:\n                break\n            }\n        }\n\n        // apply row changes\n        changes.enumerateRowChanges { (anObject, indexPath, type, newIndexPath) in\n            switch type {\n            case .insert:\n                tableView.insertRows(at: [newIndexPath!], with: .fade)\n            case .delete:\n                tableView.deleteRows(at: [indexPath!], with: .fade)\n            case .update:\n                self.configureCell(tableView.cellForRow(at: indexPath!)!, with: anObject)\n            case .move:\n                tableView.moveRow(at: indexPath!, to: newIndexPath!)\n            }\n        }\n\n        tableView.endUpdates()\n    }\n}\n```\n\n### Composing Results (Beta)\nYou can use the ComposedFirebaseResultsController to compose multiple FirebaseResultsController together.\n```\nlet controller1 = FirebaseResultsController(fetchRequest: fetchRequest1, sectionNameKeyPath: \u003coptional key path\u003e)\nlet controller2 = FirebaseResultsController(fetchRequest: fetchRequest2, sectionNameKeyPath: \u003coptional key path\u003e)\nlet controller3 = FirebaseResultsController(fetchRequest: fetchRequest3, sectionNameKeyPath: \u003coptional key path\u003e)\n\nlet controllers = [controller1, controller2, controller3]\n\nlet composedResultsController = ComposedFirebaseResultsController(controllers: controllers, composedQuery: \u003coptional composed query\u003e)\n```\n\nThe ComposedFirebaseResultsController maps index paths between the internal controllers and the external aggregated results. It also exposes a similar API to the FirebaseResultsController.\n\n\n## Contribution\n\nCreate a fork of the project into your own repository. Make all your necessary changes and create a pull request with a description on what was added or removed and details explaining the changes in lines of code. If approved, project owners will merge it.\n\n\n## Author\n\nChristian Gossain, cgossain@gmail.com\n\n## License\n\nFirebaseResultsController is released under the MIT license. See [LICENSE](https://github.com/cgossain/FirebaseResultsController/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgossain%2Ffirebaseresultscontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgossain%2Ffirebaseresultscontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgossain%2Ffirebaseresultscontroller/lists"}