findIndex(predicate: (Element) -> Bool) -> Int?

Returns the index of the first element predicate returns true for.

Parameters

  • predicate: The function invoked per iteration.

Returns

Returns the index of the found element, else nil.

[1,2,3,4,5].findIndex{$0 % 2 == 0}
// -> 1