【发布时间】:2016-02-24 18:30:01
【问题描述】:
在 swift 中,我无法弄清楚如何检查多维数组是否包含子数组。
var a: [[Int]] = []
a.append([1,2])
a.append([2,2])
a.append([3,2]) #=> [[1,2], [2,2], [3,2]]
a.contains([1,2]) #=> Contextual type '@noescape ([Int]) throws -> Bool' cannot be used with array literal.
我已经尝试了各种组合和 .indexOf 并且无法使任何工作。
我错过了什么?
【问题讨论】:
-
在您的情况下:
a.contains { $0 == [1,2] }。 indexOf 还有一个基于谓词的变体:a.indexOf { $0 == [1,2] }。