我正在尝试使用键创建一个字典作为我创建的结构,并将值作为Ints数组.但是,我一直收到错误:类型’dateStruct’不符合协议’Hashable’.我很确定我已经实现了必要的方法但由于某种原因它仍然不起作用.这是我的结构与实现的协议:
- struct dateStruct {
- var year: Int
- var month: Int
- var day: Int
- var hashValue: Int {
- return (year+month+day).hashValue
- }
- static func == (lhs: dateStruct,rhs: dateStruct) -> Bool {
- return lhs.hashValue == rhs.hashValue
- }
- static func < (lhs: dateStruct,rhs: dateStruct) -> Bool {
- if (lhs.year < rhs.year) {
- return true
- } else if (lhs.year > rhs.year) {
- return false
- } else {
- if (lhs.month < rhs.month) {
- return true
- } else if (lhs.month > rhs.month) {
- return false
- } else {
- if (lhs.day < rhs.day) {
- return true
- } else {
- return false
- }
- }
- }
- }
- }
任何人都可以向我解释为什么我仍然会收到错误?