I have a tree data structure where each node has an id, type and children:
final class Node: Equatable, Hashable {
var id: String = UUID().uuidString
var type: String = ""
var children: [Node] = []
func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(type)
hasher.combine(children)
}
public static func ==(lhs: Node, rhs: Node) -> Bool {
lhs.id == rhs.id && lhs.type == rhs.type && lhs.children == rhs.children
}
func add(child: Node) { // added as requested. called from a Button
self.children.append(child)
}
}
When I run the program and start adding nodes, either at the top level (an array stored in a StateObject) or beneath an existing node, I get Fatal error: Duplicate keys of type 'ArraySlice<Node>' were found in a Dictionary
. This happens not the first, sometimes not the second, but the 3rd or 4th time I add a node. Is there a dictionary in the system somewhere used by SwiftUI or otherwise? I do not have any dictionaries in my data structures, nor am I slicing any arrays that I am aware of. This worked until yesterday...
Thx!