Last active
February 3, 2023 10:24
-
-
Save emiliopavia/d3a0cdaef648fb782302054d95e5ae9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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