Skip to content

Instantly share code, notes, and snippets.

@emiliopavia
Created December 6, 2019 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emiliopavia/f9c8a1ee2aa41fc314bfa7e8f9125bb9 to your computer and use it in GitHub Desktop.
Save emiliopavia/f9c8a1ee2aa41fc314bfa7e8f9125bb9 to your computer and use it in GitHub Desktop.
import UIKit
enum MySection: Hashable {
case items
}
class 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("B")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment