IGListIndexSetResult updates contains index of old collection
README and documentationIGListKit version: 2.1.0In IGListIndexSetResult documentation can be read:
/**
The indexes in the new collection that need updated.
*/
@property (nonatomic, strong, readonly) NSIndexSet *updates;
So it's expected that all indexes on updates refer to objects in new collection, although if you have an old collection with two elements and a new collection only with the second element updated we got an index on updates that are out of bounds the new collection. This test will fail on the last assert:
func testDiffingSwiftClassWithDeleteAndUpdates() {
let o = [SwiftClass(id: 0, value: "a"), SwiftClass(id: 1, value: "b")]
let n = [SwiftClass(id: 1, value: "c")]
let result = IGListDiff(o, n, .equality)
XCTAssertEqual(result.deletes, IndexSet(integer: 0))
XCTAssertEqual(result.inserts.count, 0)
XCTAssertEqual(result.moves.count, 0)
XCTAssertEqual(result.updates, IndexSet(integer: 0))
}
In this case results.updates contains IndexSet(integer: 1), which can only refers to the old collection.
My doubt here is if the issue is on the documentation or this is a bug.
Thanks @diogot ! Sounds like a bug. 👍
cc @rnystrom
@diogot - Do you want to submit a PR with a fix?
(we should add this test, too 😄 )
Typically reloads are expressed using indexes from before the update – e.g. if you call reloadItems: UICollectionView expects old indexes. Maybe the documentation should be changed? You can always map to the new indexes if needed.
@diogot @Adlai-Holler is correct, the documentation (here and here) is out of date, would love a PR to fix that!
The diff result is designed for UICollectionView and UITableView batch updates where the reload index is relative to the _old_ index. Though we don't use reloadItemsAtIndexPaths: explicitly, it's still relevant.
We have this expectation covered in this unit test.
Done in #413