Latest 1.0.0
Homepage https://github.com/fphilipe/PHFArrayComparator
License MIT
Authors

Easily animate table changes. This animation shows two table views side by
side, the left one does not use animations while the right one does.

demo

This little class is intended to be used with UITableView and other collection
like views. It’s purpose is to facilitate the smooth update of displayed data.
It does that by telling you what is gone, what moved, and what is new in the
data. These can then be directly translated to table view methods that insert,
move, and delete rows or sections.

Installation

The prefered way is to use CococaPods.

pod 'PHFArrayComparator', '~> 1.0.0'

If you can’t use CocoaPods for some reason (you really should though, it’s the
cool kid on the block), then grab the PHFRefreshControl.{h,m} files and put it
in your project. The code uses ARC, so make sure to turn that on for this file
if you’re not already using ARC.

Usage

NSArray *a = @[ @"A", @"B", @"C" ];
NSArray *b = @[ @"X", @"C", @"B", @"D" ];
NSDictionary *instructions = [PHFArrayComparator compareOldArray:a withNewArray:b];

instructions contains three keys:

  • PHFArrayComparatorDeletesKey: An array of arrays containing two NSNumbers
    indicating index and count of items that were removed from the old array, e.g.
    [2, 3] means 3 items were removed at index 2.
  • PHFArrayComparatorMovesKey: An array of arrays containing two NSNumbers
    indicating the old and new index of a persisted item (i.e. an item present) in
    terms of the old array that needed to be swapped with another persited item in
    order to respect the new item order.
  • PHFArrayComparatorInsertsKey: An array of arrays containing two NSNumbers
    indicating index and count of items that were inserted in the new array.

Thus, the content of instructions looks as follows (in JSON notation).

{
  "PHFArrayComparatorDeletesKey": [[0, 1]],
  "PHFArrayComparatorMovesKey":   [[2, 1], [1, 2]],
  "PHFArrayComparatorInsertsKey": [[0, 1], [3, 1]]
}

For full working examples, have a look at the Xcode project in Examples/.

Small Print

License

PHFArrayComparator is released under the MIT license.

Author

Philipe Fatio (@fphilipe)

Bitdeli Badge

Latest podspec

{
    "name": "PHFArrayComparator",
    "version": "1.0.0",
    "summary": "Animated table updates made easy.",
    "description": "This little class is intended to be used with UITableView and other collectionnlike views.  It's purpose is to facilitate the smooth update of displayed data.nIt does that by telling you what is gone, what moved, and what is new in thendata.  These can then be directly translated to table view methods that insert,nmove, and delete rows or sections.n",
    "homepage": "https://github.com/fphilipe/PHFArrayComparator",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Philipe Fatio": "[email protected]"
    },
    "source": {
        "git": "https://github.com/fphilipe/PHFArrayComparator.git",
        "tag": "v1.0.0"
    },
    "source_files": "PHFArrayComparator.{h,m}",
    "preserve_paths": [
        "LICENSE",
        "README.md"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This