2

In swift, I cannot figure out how to check if a multi-dimensional array contains a child array.

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.

I've tried all kinds of combinations and .indexOf and can't get anything to work.

What am I missing?

1
  • In your case: a.contains { $0 == [1,2] }. indexOf has also a predicate-based variant: a.indexOf { $0 == [1,2] }. Commented Nov 22, 2015 at 17:29

1 Answer 1

3

You can do this with the predicate form of contains:

a.contains {$0 == [1,2]}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.