加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

function – 在Swift 2.0中使用reduce()时出错

发布时间:2020-12-14 05:22:31 所属栏目:百科 来源:网络整理
导读:注意:这也适用于 Swift 3.0 当我尝试使用reduce函数时,我收到一条错误消息: reduce is unavailable: call the ‘reduce()’ method on the sequence 我已经知道如何使用enumerate()函数执行此操作,但我似乎无法解决此问题.这是返回错误的代码行: var hash
注意:这也适用于 Swift 3.0

当我尝试使用reduce函数时,我收到一条错误消息:

reduce is unavailable: call the ‘reduce()’ method on the sequence

我已经知道如何使用enumerate()函数执行此操作,但我似乎无法解决此问题.这是返回错误的代码行:

var hashValue: Int {
    return reduce(blocks,0) { $0.hashValue ^ $1.hashValue }
}
你修复它的方法与使用enumerate()修复问题的方法相同.在Swift 2中,reduce已作为全局函数被删除,并已作为实例方法添加到通过协议扩展符合SequenceType协议的所有对象上.用法如下.
var hashValue: Int {
    return blocks.reduce(0) { $0.hashValue ^ $1.hashValue }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读