Skip to content

Instantly share code, notes, and snippets.

@hellaandrew
hellaandrew / DiffablePlayground.playground
Last active April 10, 2020 07:30
This Xcode playground illustrates an issue with applying a new snapshot to the dataSource with animatingDifferences set to `true`
/// # DESCRIPTION
/// This playground generates a random amount of sections containing a random amount of items.
/// Each item has a `count` property which is meant to indicate how many of that item there is in the section which is also a random number.
/// The collection item cells display an item's `title`, `description` and `count`. There are two buttons, and `+` and `-` which increments or decrements the item's count value.
/// Each section in the collection view will draw a section header cell, which displays the section's `title` and how many items total there are in its section (all of the item counts added together)
/// If an items count ever reaches 0, the item is removed from the collection.
///
/// # ISSUE
/// The section headers data doesn't update if I apply the updated snapshot to the dataSource with `animatingDifferences` set to `true`.
/// The entire list updates correctly if I increment or decrement the number when it's above 0 because the logic I have has `animatingDifferences` set to `false