我正在尝试实现swift字典的实际实现。我想知道如何忽略输出代码中的数组变量boxes。难道这正是字典的实际实现吗?
struct Box<U,V> where U: Hashable {
var que: U
var ans:V
fileprivate var boxes = [Box]()
init(_ que: U,ans: V) {
self.que = que
self.ans = ans
}
mutating func addBox(with que: U, ans: V) {
boxes.append(Box(que, ans: ans))
}
mutating func deleteBox(_ que: U) {
for (index, value) in boxes.enumerated() {
if value.que == que {
boxes.remove(at: index)
}
}
}
}
class Display {
func show() {
var dict = Box(1, ans: "One")
print(dict)
}
}
let obj = Display()
obj.show()
// Output:Box(que:1,ans:“ One”,boxes:[])
我想知道如何忽略输出代码中的数组变量框
使Box符合CustomStringConvertible并提供您自己的description
实现。
这也是字典的实际实现吗?
没有