Created
December 6, 2019 09:03
-
-
Save emiliopavia/f9c8a1ee2aa41fc314bfa7e8f9125bb9 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 | |
} | |
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