Skip to content

Instantly share code, notes, and snippets.

@emiliopavia
Last active February 3, 2023 10:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emiliopavia/d3a0cdaef648fb782302054d95e5ae9d to your computer and use it in GitHub Desktop.
Save emiliopavia/d3a0cdaef648fb782302054d95e5ae9d to your computer and use it in GitHub Desktop.
import UIKit
enum MySection: Hashable {
case items
}
struct MyItem: Hashable {
let identifier = UUID()
var value: String?
func hash(into hasher: inout Hasher) {
hasher.combine(identifier)
}
static func == (lhs: MyItem, rhs: MyItem) -> Bool {
return lhs.identifier == rhs.identifier
}
}
var item = MyItem()
item.value = "A"
var snapshot = NSDiffableDataSourceSnapshot<MySection, MyItem>()
snapshot.appendSections([.items])
snapshot.appendItems([item], toSection: .items)
print(snapshot.itemIdentifiers.map({ $0.value }))
// prints [Optional("A")]
item.value = "B"
snapshot.reloadItems([item])
print(snapshot.itemIdentifiers.map({ $0.value }))
// prints [Optional("A")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment