<commit_before># LMArrayChangeSets

[![CI Status](http://img.shields.io/travis/cdann/LMArrayChangeSets.svg?style=flat)](https://travis-ci.org/cdann/LMArrayChangeSets)
[![Version](https://img.shields.io/cocoapods/v/LMArrayChangeSets.svg?style=flat)](http://cocoadocs.org/docsets/LMArrayChangeSets)
[![License](https://img.shields.io/cocoapods/l/LMArrayChangeSets.svg?style=flat)](http://cocoadocs.org/docsets/LMArrayChangeSets)
[![Platform](https://img.shields.io/cocoapods/p/LMArrayChangeSets.svg?style=flat)](http://cocoadocs.org/docsets/LMArrayChangeSets)

## Usage

This is a set of simple categories that help with a common pattern I use for updating array-backed UITableViews and UICollectionViews.

It extends NSArray to provide simple diff functionality. You provide the initial array, the updated array, and an identity comparison block, and the method returns an NSDictionary of NSIndexSets with the inserted, deleted and moved indexes.

Categories are provided for UITableView and UICollectionView that take the IndexSet dictionary and perform the updates as a batch with row/cell animation.

### Objective-C Examples

#### UICollectionView

```
- (void)updateWithItems:(NSArray *)items {
    
    NSDictionary* indexChangeSets = [NSArray indexChangeSetsForUpdatedList:items
                                                              previousList:self.items
                                                        identityComparator:^NSComparisonResult(NSDictionary* a, NSDictionary* b) {
                                                            // This block should determine if the items in the list have the same identity or not
                                                            return [a[@"id"] compare:b[@"id"]];
                                                        }];
    <commit_msg>Specify code sample language in README file.<commit_after># LMArrayChangeSets

[![CI Status](http://img.shields.io/travis/cdann/LMArrayChangeSets.svg?style=flat)](https://travis-ci.org/cdann/LMArrayChangeSets)
[![Version](https://img.shields.io/cocoapods/v/LMArrayChangeSets.svg?style=flat)](http://cocoadocs.org/docsets/LMArrayChangeSets)
[![License](https://img.shields.io/cocoapods/l/LMArrayChangeSets.svg?style=flat)](http://cocoadocs.org/docsets/LMArrayChangeSets)
[![Platform](https://img.shields.io/cocoapods/p/LMArrayChangeSets.svg?style=flat)](http://cocoadocs.org/docsets/LMArrayChangeSets)

## Usage

This is a set of simple categories that help with a common pattern I use for updating array-backed UITableViews and UICollectionViews.

It extends NSArray to provide simple diff functionality. You provide the initial array, the updated array, and an identity comparison block, and the method returns an NSDictionary of NSIndexSets with the inserted, deleted and moved indexes.

Categories are provided for UITableView and UICollectionView that take the IndexSet dictionary and perform the updates as a batch with row/cell animation.

### Objective-C Examples

#### UICollectionView

```objectivec
- (void)updateWithItems:(NSArray *)items {
    
    NSDictionary* indexChangeSets = [NSArray indexChangeSetsForUpdatedList:items
                                                              previousList:self.items
                                                        identityComparator:^NSComparisonResult(NSDictionary* a, NSDictionary* b) {
                                                            // This block should determine if the items in the list have the same identity or not
                                                            return [a[@"id"] compare:b[@"id"]];
                                                        }];
    
{'fraction_non_alphanumeric': 0.09426786199402336, 'fraction_numerical': 0.0, 'mean_word_length': 2.5886939571150096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5743884', 'n_tokens_mistral': 952, 'n_tokens_neox': 913, 'n_words': 247}