我有一个定义词典的类:
class InventoryDictionary <U : Hashable, V> : Equatable {
var dictionary : [ U : V? ] = [:]
static func ==(lhs: InventoryDictionary, rhs: InventoryDictionary) -> Bool {
return lhs.dictionary.keys == rhs.dictionary.keys
&& lhs.dictionary.values == rhs.dictionary.values
}
}
Xcode显示错误:
Referencing operator function '==' on 'Equatable' requires that 'Dictionary.Values' conform to 'Equatable'
我正在努力使InventoryDicary符合Equatable
SWIFT协议.
在==
重载函数中,可以比较dictionary.keys
是否相等,但不能比较值(这在某种程度上是可以理解的).
但从消息中我不清楚,如果不编写代码判断每个V
(值),这是否可以解决,或者是否有某种方法可以使SWIFT-GENERIC V
相等.
解决这一问题的好方法是什么?