Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
注意:这也适用于 Swift 3.0
当我尝试使用该reduce功能时,我收到一条错误消息:
reduce
reduce 不可用:在序列上调用 'reduce()' 方法
我已经想出了如何使用该enumerate()功能来做到这一点,但我似乎无法解决这个问题。这是返回错误的代码行:
enumerate()
var hashValue: Int { return reduce(blocks, 0) { $0.hashValue ^ $1.hashValue } }
您解决此问题的方式与解决问题的方式相同enumerate()。在 Swift 2 中,reduce 已作为全局函数被移除,并已作为实例方法添加到所有SequenceType通过协议扩展符合协议的对象上。用法如下。
SequenceType
var hashValue: Int { return blocks.reduce(0) { $0.hashValue ^ $1.hashValue } }