小编Sen*_*ian的帖子

在Swift 4中使用reduce时,"上下文闭包类型需要2个参数"错误

以下代码在Swift 3中编译

extension Array where Element: Equatable {
    var removeDuplicate: [Element] {
        return reduce([]){ $0.0.contains($0.1) ? $0.0 : $0.0 + [$0.1] }
    }
}
Run Code Online (Sandbox Code Playgroud)

但会产生错误

错误:上下文闭包类型'(_,_) - > _'需要2个参数,但在闭包体中使用了1

在Swift 4.如何转换此代码以在Swift 4中编译?

arrays reduce swift equatable swift4

6
推荐指数
1
解决办法
3442
查看次数

标签 统计

arrays ×1

equatable ×1

reduce ×1

swift ×1

swift4 ×1