本文介绍了快速函数和闭包可以符合Hashable吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想使用Set函数或闭包.这是我的处理方法:

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:

这是死胡同吗?

推荐答案

是的,这是一个死胡同.哈希并不是您真正的问题;无法确定两个闭包是否相等(这是Hashable的基本要求).

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).

这篇关于快速函数和闭包可以符合Hashable吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 06:55