{"id":19773917,"url":"https://github.com/badoo/ios-collection-batch-updates","last_synced_at":"2025-06-15T09:36:17.042Z","repository":{"id":56903032,"uuid":"42930351","full_name":"badoo/ios-collection-batch-updates","owner":"badoo","description":"Safely perform batch updates in UITableView and UICollectionView","archived":false,"fork":false,"pushed_at":"2018-04-30T14:49:15.000Z","size":2296,"stargazers_count":122,"open_issues_count":0,"forks_count":21,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-16T15:35:35.535Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","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/badoo.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":"2015-09-22T11:44:56.000Z","updated_at":"2024-10-12T12:16:07.000Z","dependencies_parsed_at":"2022-08-21T01:50:47.135Z","dependency_job_id":null,"html_url":"https://github.com/badoo/ios-collection-batch-updates","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fios-collection-batch-updates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fios-collection-batch-updates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fios-collection-batch-updates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badoo%2Fios-collection-batch-updates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badoo","download_url":"https://codeload.github.com/badoo/ios-collection-batch-updates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251761236,"owners_count":21639573,"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":[],"created_at":"2024-11-12T05:11:31.428Z","updated_at":"2025-04-30T18:32:26.812Z","avatar_url":"https://github.com/badoo.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BMACollectionBatchUpdates [![Build Status](https://api.travis-ci.org/badoo/ios-collection-batch-updates.svg)](https://travis-ci.org/badoo/ios-collection-batch-updates)  [![codecov.io](https://codecov.io/github/badoo/ios-collection-batch-updates/coverage.svg?branch=master)](https://codecov.io/github/badoo/ios-collection-batch-updates?branch=master) [![CocoaPods Compatible](https://img.shields.io/cocoapods/v/BMACollectionBatchUpdates.svg)](https://img.shields.io/cocoapods/v/BMACollectionBatchUpdates.svg)\n`BMACollectionBatchUpdates` is a set of classes to generate updates and extensions to `UICollectionView` and `UITableView` to perform them safely in a batch manner.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"./demoimages/demo.gif\" /\u003e\n\u003c/div\u003e\n\n## How to use\n\nIn order to generate the mentioned updates it has to make collection item and section conform the `BMAUpdatableCollectionItem` and`BMAUpdatableCollectionItem` protocols respectively:\n\n```objectivec\n@interface BMAExampleItemsSection : NSObject \u003cBMAUpdatableCollectionSection\u003e\n@end\n\n@interface BMAExampleItem : NSObject \u003cBMAUpdatableCollectionItem\u003e\n@end\n```\n\nOnce both old and new data models are available, it has to calculate changes and apply them:\n\n```objectivec\n@implementation BMAExampleCollectionViewController\n\n- (void)setSections:(NSArray *)sections {\n\t[BMACollectionUpdate calculateUpdatesForOldModel:self.sections\n                                            newModel:sections\n                               sectionsPriorityOrder:nil\n                                eliminatesDuplicates:YES\n                                          completion:^(NSArray *sections, NSArray *updates) {\n                                          \t\t[self.collectionView bma_performBatchUpdates:updates applyChangesToModelBlock:^{\n\t\t\t\t\t\t\t\t\t\t\t        _sections = sections;\n\t\t\t\t\t\t\t\t\t\t\t    } reloadCellBlock:^(UICollectionViewCell *cell, NSIndexPath *indexPath) {\n\t\t\t\t\t\t\t\t\t\t\t        [self reloadCell:cell atIndexPath:indexPath];\n\t\t\t\t\t\t\t\t\t\t\t    } completionBlock:nil];\n                                          }];\n}\n\n@end\n```\n\n```objectivec\n@implementation BMAExampleTableViewController\n\n- (void)setSections:(NSArray *)sections {\n\t[BMACollectionUpdate calculateUpdatesForOldModel:self.sections\n                                            newModel:sections\n                               sectionsPriorityOrder:nil\n                                eliminatesDuplicates:YES\n                                          completion:^(NSArray *sections, NSArray *updates) {\n                                          \t\t[self.collectionView bma_performBatchUpdates:updates applyChangesToModelBlock:^{\n\t\t\t\t\t\t\t\t\t\t\t        _sections = sections;\n\t\t\t\t\t\t\t\t\t\t\t    } reloadCellBlock:^(UITableViewCell *cell, NSIndexPath *indexPath) {\n\t\t\t\t\t\t\t\t\t\t\t        [self reloadCell:cell atIndexPath:indexPath];\n\t\t\t\t\t\t\t\t\t\t\t    } completionBlock:nil];\n                                          }];\n}\n\n@end\n```\n\n### Generating cell update for existing BMAUpdatableCollectionItem\n\n`BMAUpdatableCollectionItem` conforms to `NSObject` protocol and by doing so it provides `isEqual` method for comparing items. In most cases comparing uids in `isEqual` will be enough, but sometimes your model may contain additional properties that can change and requie cell update.\n\nSimple example: online status which can be either online or offline. When it changes we need to gerenrate cell update for this item. To detect this change `isEqual` can be implemented in following way:\n\n```objectivec\n- (BOOL)isEqual:(id)object {\n    if (self == object) {\n        return YES;\n    }\n\n    if (![object isKindOfClass:[self class]]) {\n        return NO;\n    }\n\n    BMAExampleItem *item = (BMAExampleItem *)object;\n    return [self.uid isEqual:item.uid] \u0026\u0026 self.isOnline == item.isOnline;\n}\n\n@end\n```\n\n## How to install\n\n### Using CocoaPods\n\n\n1. Include the following line in your `Podfile`:\n\n    ```\n    pod 'BMACollectionBatchUpdates', '~\u003e 1.1'\n    ```\n\n\tIf you like to live on the bleeding edge, you can use the `master` branch with:\n\n    ```\n    pod 'BMACollectionBatchUpdates', :git =\u003e 'https://github.com/badoo/ios-collection-batch-updates'\n    ```\n\n2. Run `pod install`\n\n### Manually\n\n1. Clone, add as a submodule or [download.](https://github.com/badoo/ios-collection-batch-updates/archive/master.zip)\n2. Add all the files under `BMACollectionBatchUpdates` to your project.\n3. Make sure your project is configured to use ARC.\n\n## License\n\nSource code is distributed under MIT license.\n\n## Blog\nRead more on our [tech blog](http://techblog.badoo.com/) or explore our other [open source projects](https://github.com/badoo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadoo%2Fios-collection-batch-updates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadoo%2Fios-collection-batch-updates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadoo%2Fios-collection-batch-updates/lists"}