index(_:ofObjectPassingTest:)
Returns the index of an object in the ordered set that passes a test in a given block for a given set of enumeration options.
Declaration
func index(_ opts: NSEnumerationOptions = [], ofObjectPassingTest predicate: (Any, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> IntParameters
- opts:
A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).
- predicate:
The block to apply to elements in the ordered set.
The block takes three arguments:
- obj
The element in the array.
- idx
The index of the element in the ordered set.
- stop
A reference to a Boolean value. The block can set the value to True to stop further processing of the set. The
stopargument is an out-only argument. You should only ever set this value to True within the block.
The block returns a Boolean value that indicates whether obj passed the test.
Return Value
The index whose corresponding value in the ordered set passes the test specified by predicate and opts. If no objects in the ordered set pass the test, returns NSNotFound.
Discussion
By default, the enumeration starts with the first object and continues serially through the ordered set to the last object. You can specify concurrent and/or reverse as enumeration options to modify this behavior.
See Also
Accessing Set Members
contains(_:)enumerateObjects(at:options:using:)enumerateObjects(_:)enumerateObjects(options:using:)firstObjectlastObjectobject(at:)subscript(_:)objects(at:)index(of:)index(of:inSortedRange:options:usingComparator:)index(ofObjectAt:options:passingTest:)index(ofObjectPassingTest:)indexes(ofObjectsAt:options:passingTest:)indexes(ofObjectsPassingTest:)