Swift: 'Hashable.hashValue' is deprecated as a protocol requirement;

南笙酒味 提交于 2019-11-29 03:22:56

As the warning says, now you should implement the hash(into:) function instead.

func hash(into hasher: inout Hasher) {
    switch self {
    case .mention: hasher.combine(-1)
    case .hashtag: hasher.combine(-2)
    case .url: hasher.combine(-3)
    case .custom(let regex): hasher.combine(regex) // assuming regex is a string, that already conforms to hashable
    }
}

TIP: you don't need to make the enum explicitly conforms to Equatable because Hashable extends it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!