Fix id of Items, saving
This commit is contained in:
@ -7,11 +7,17 @@ class Item: ChangeObservingItem, Identifiable {
|
||||
@Published
|
||||
private var changeToggle = false
|
||||
|
||||
/// A session-id for the item for identification
|
||||
let id = UUID()
|
||||
|
||||
/// The unique, persistent identifier of the item
|
||||
///
|
||||
/// This identifier is not used for `Identifiable`, since it may be changed through the UI.
|
||||
@Published
|
||||
var id: String
|
||||
var identifier: String
|
||||
|
||||
init(content: Content, id: String) {
|
||||
self.id = id
|
||||
self.identifier = id
|
||||
super.init(content: content)
|
||||
|
||||
observeChanges()
|
||||
@ -44,14 +50,14 @@ class Item: ChangeObservingItem, Identifiable {
|
||||
}
|
||||
|
||||
var itemId: ItemId {
|
||||
.init(type: itemType, id: id)
|
||||
.init(type: itemType, id: identifier)
|
||||
}
|
||||
}
|
||||
|
||||
extension Item: Equatable {
|
||||
|
||||
static func == (lhs: Item, rhs: Item) -> Bool {
|
||||
lhs.id == rhs.id && lhs.itemType == rhs.itemType
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,13 +65,12 @@ extension Item: Hashable {
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
hasher.combine(itemType)
|
||||
}
|
||||
}
|
||||
|
||||
extension Item: Comparable {
|
||||
|
||||
static func < (lhs: Item, rhs: Item) -> Bool {
|
||||
lhs.id < rhs.id && lhs.itemType < rhs.itemType
|
||||
lhs.identifier < rhs.identifier && lhs.itemType < rhs.itemType
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user