can swift functions and closures conform to Hashable?

非 Y 不嫁゛ 提交于 2020-01-30 05:18:37

问题


Suppose I want to have a Set of functions or closures. Here's how I would go about it:

typealias HandlerX = () -> ()
static var handlersX = Set<HandlerX>()

This produces the following compiler error:

Type 'HandlerX' (aka '() -> ()') does not conform to protocol 'Hashable'

Is this a dead end?


回答1:


Yes, this is a dead end. Hashable isn't really your problem; there's no way to decide whether two closures are Equal (which is a base requirement of Hashable).



来源:https://stackoverflow.com/questions/35161853/can-swift-functions-and-closures-conform-to-hashable

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