Mac Developer Library

Developer

Foundation Framework Reference NSIndexSet Class Reference

Options
Deployment Target:

On This Page
Language:

NSIndexSet

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.3 and later.

The NSIndexSet class represents an immutable collection of unique unsigned integers, known as indexes because of the way they are used. This collection is referred to as an index set. Indexes must be in the range 0 .. NSNotFound - 1.

You use index sets in your code to store indexes into some other data structure. For example, given an NSArray object, you could use an index set to identify a subset of objects in that array.

You should not use index sets to store an arbitrary collection of integer values because index sets store indexes as sorted ranges. This makes them more efficient than storing a collection of individual integers. It also means that each index value can only appear once in the index set.

The designated initializers of the NSIndexSet class are: init, initWithIndexesInRange:, and initWithIndexSet:.

You must not subclass the NSIndexSet class.

The mutable subclass of NSIndexSet is NSMutableIndexSet.

  • Creates an empty index set.

    Declaration

    Objective-C

    + (instancetype)indexSet

    Return Value

    NSIndexSet object with no members.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in OS X v10.3 and later.

    See Also

    – init

  • Creates an index set with an index.

    Declaration

    Objective-C

    + (instancetype)indexSetWithIndex:(NSUInteger)index

    Parameters

    index

    An index. Must be in the range 0 .. NSNotFound - 1.

    Return Value

    NSIndexSet object containing index.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in OS X v10.3 and later.

  • Creates an index set with an index range.

    Declaration

    Objective-C

    + (instancetype)indexSetWithIndexesInRange:(NSRange)indexRange

    Parameters

    indexRange

    An index range. Must be in the range 0 .. NSNotFound - 1.

    Return Value

    NSIndexSet object containing indexRange.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in OS X v10.3 and later.

  • init - init Available in OS X v10.3 through OS X v10.9

    Initializes an allocated NSIndexSet object.

    Declaration

    Objective-C

    - (instancetype)init

    Return Value

    Initialized, empty NSIndexSet object.

    Discussion

    This method is a designated initializer for NSIndexSet.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in OS X v10.3 through OS X v10.9.

    See Also

    + indexSet

  • Initializes an allocated NSIndexSet object with an index.

    Declaration

    Swift

    convenience init(index index: Int)

    Objective-C

    - (instancetype)initWithIndex:(NSUInteger)index

    Parameters

    index

    An index. Must be in the range 0 .. NSNotFound - 1.

    Return Value

    Initialized NSIndexSet object with index.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Initializes an allocated NSIndexSet object with an index range.

    Declaration

    Swift

    init(indexesInRange indexRange: NSRange)

    Objective-C

    - (instancetype)initWithIndexesInRange:(NSRange)indexRange

    Parameters

    indexRange

    An index range. Must be in the range 0 .. NSNotFound - 1..

    Return Value

    Initialized NSIndexSet object with indexRange.

    Discussion

    This method raises an NSRangeException when indexRange would add an index that exceeds the maximum allowed value for unsigned integers.

    This method is a designated initializer for NSIndexSet.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • init(indexSet:) - initWithIndexSet: Designated Initializer

    Initializes an allocated NSIndexSet object with an index set.

    Declaration

    Swift

    init(indexSet indexSet: NSIndexSet)

    Objective-C

    - (instancetype)initWithIndexSet:(NSIndexSet *)indexSet

    Parameters

    indexSet

    An index set.

    Return Value

    Initialized NSIndexSet object with indexSet.

    Discussion

    This method is a designated initializer for NSIndexSet.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Indicates whether the index set contains a specific index.

    Declaration

    Swift

    func containsIndex(_ index: Int) -> Bool

    Objective-C

    - (BOOL)containsIndex:(NSUInteger)index

    Parameters

    index

    Index being inquired about.

    Return Value

    YEStrue when the index set contains index, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Indicates whether the receiving index set contains a superset of the indexes in another index set.

    Declaration

    Swift

    func containsIndexes(_ indexSet: NSIndexSet) -> Bool

    Objective-C

    - (BOOL)containsIndexes:(NSIndexSet *)indexSet

    Parameters

    indexSet

    Index set being inquired about.

    Return Value

    YEStrue when the receiving index set contains a superset of the indexes in indexSet, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Indicates whether the index set contains the indexes represented by an index range.

    Declaration

    Swift

    func containsIndexesInRange(_ indexRange: NSRange) -> Bool

    Objective-C

    - (BOOL)containsIndexesInRange:(NSRange)indexRange

    Parameters

    indexRange

    The index range being inquired about.

    Return Value

    YEStrue when the index set contains the indexes in indexRange, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Indicates whether the index set contains any of the indexes in a range.

    Declaration

    Swift

    func intersectsIndexesInRange(_ indexRange: NSRange) -> Bool

    Objective-C

    - (BOOL)intersectsIndexesInRange:(NSRange)indexRange

    Parameters

    indexRange

    Index range being inquired about.

    Return Value

    YEStrue when the index set contains one or more of the indexes in indexRange, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • count count Property

    The number of indexes in the index set. (read-only)

    Declaration

    Swift

    var count: Int { get }

    Objective-C

    @property(readonly) NSUInteger count

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Returns the number of indexes in the index set that are members of a given range.

    Declaration

    Swift

    func countOfIndexesInRange(_ indexRange: NSRange) -> Int

    Objective-C

    - (NSUInteger)countOfIndexesInRange:(NSRange)indexRange

    Parameters

    indexRange

    Index range being inquired about.

    Return Value

    Number of indexes in the index set that are members of indexRange.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

    See Also

    – count

  • Returns the index of the first object that passes the predicate Block test.

    Declaration

    Swift

    func indexPassingTest(_ predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int

    Objective-C

    - (NSUInteger)indexPassingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate

    Parameters

    predicate

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    The Block returns a Boolean value that indicates whether obj passed the test.

    Return Value

    The index of the first object that passes the predicate test.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Returns an NSIndexSet containing the receiving index set’s objects that pass the Block test.

    Declaration

    Swift

    func indexesPassingTest(_ predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet

    Objective-C

    - (NSIndexSet *)indexesPassingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate

    Parameters

    predicate

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    The Block returns a Boolean value that indicates whether obj passed the test.

    Return Value

    An NSIndexSet containing the indexes of the receiving index set that passed the predicate Block test.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Returns the index of the first object that passes the predicate Block test using the specified enumeration options.

    Declaration

    Swift

    func indexWithOptions(_ opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int

    Objective-C

    - (NSUInteger)indexWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate

    Parameters

    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). See NSEnumerationOptions for the supported values.

    predicate

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    The Block returns a Boolean value that indicates whether obj passed the test.

    Return Value

    The index of the first object that passes the predicate test.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Returns an NSIndexSet containing the receiving index set’s objects that pass the Block test using the specified enumeration options.

    Declaration

    Swift

    func indexesWithOptions(_ opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet

    Objective-C

    - (NSIndexSet *)indexesWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate

    Parameters

    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). See NSEnumerationOptions for the supported values.

    predicate

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    The Block returns a Boolean value that indicates whether obj passed the test.

    Return Value

    An NSIndexSet containing the indexes of the receiving index set that passed the predicate Block test.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Returns the index of the first object in the specified range that passes the predicate Block test.

    Declaration

    Swift

    func indexInRange(_ range: NSRange, options opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int

    Objective-C

    - (NSUInteger)indexInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate

    Parameters

    range

    The range of indexes to test.

    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). See NSEnumerationOptions for the supported values.

    predicate

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    The Block returns a Boolean value that indicates whether obj passed the test.

    Return Value

    The index of the first object that passes the predicate test.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Returns an NSIndexSet containing the receiving index set’s objects in the specified range that pass the Block test.

    Declaration

    Swift

    func indexesInRange(_ range: NSRange, options opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet

    Objective-C

    - (NSIndexSet *)indexesInRange:(NSRange)range options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(NSUInteger idx, BOOL *stop))predicate

    Parameters

    range

    The range of indexes to test.

    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). See NSEnumerationOptions for the supported values.

    predicate

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    The Block returns a Boolean value that indicates whether obj passed the test.

    Return Value

    An NSIndexSet containing the indexes of the receiving index set that passed the predicate Block test.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Enumerates over the ranges in the range of objects using the block

    Declaration

    Swift

    func enumerateRangesInRange(_ range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (void)enumerateRangesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange range, BOOL *stop))block

    Parameters

    range

    The range of items to enumerate. If the range intersects a range of the receiver's indexes, then that intersection will be passed to the block.

    opts

    A bitmask that specifies the NSEnumerationOptions for the enumeration.

    block

    The block to apply to elements in the index set.

    The block takes two arguments:

    range

    The range of elements.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YEStrue within the Block.

    Discussion

    By default, the enumeration starts with the first object and continues serially through the indexed set range to the last object in the range. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

    This method executes synchronously.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Executes a given block using each object in the index set, in the specified ranges.

    Declaration

    Swift

    func enumerateRangesUsingBlock(_ block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (void)enumerateRangesUsingBlock:(void (^)(NSRange range, BOOL *stop))block

    Parameters

    block

    The block to apply to elements in the index set.

    The block takes two arguments:

    range

    The range of objects of the elements in the index set.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YEStrue within the Block.

    Discussion

    If the Block parameter is nil this method will raise an exception.

    This method executes synchronously.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Executes a given block using each object in the index set, in the specified ranges.

    Declaration

    Swift

    func enumerateRangesWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (void)enumerateRangesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSRange range, BOOL *stop))block

    Parameters

    opts

    A bitmask that specifies the NSEnumerationOptions for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

    block

    The block to apply to elements in the index set.

    The block takes two arguments:

    range

    The range of objects of the elements in the index set.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YEStrue within the Block.

    Discussion

    By default, the enumeration starts with the first object and continues serially through the indexed set range to the last object in the range. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

    This method executes synchronously.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Indicates whether the indexes in the receiving index set are the same indexes contained in another index set.

    Declaration

    Swift

    func isEqualToIndexSet(_ indexSet: NSIndexSet) -> Bool

    Objective-C

    - (BOOL)isEqualToIndexSet:(NSIndexSet *)indexSet

    Parameters

    indexSet

    Index set being inquired about.

    Return Value

    YEStrue when the indexes in the receiving index set are the same indexes indexSet contains, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • The first index in the index set. (read-only)

    Declaration

    Swift

    var firstIndex: Int { get }

    Objective-C

    @property(readonly) NSUInteger firstIndex

    Discussion

    First index in the index set or NSNotFound when the index set is empty.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

    See Also

    – lastIndex

  • lastIndex lastIndex Property

    The last index in the index set. (read-only)

    Declaration

    Swift

    var lastIndex: Int { get }

    Objective-C

    @property(readonly) NSUInteger lastIndex

    Discussion

    Last index in the index set or NSNotFound when the index set is empty.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

    See Also

    – firstIndex

  • Returns either the closest index in the index set that is less than a specific index or the not-found indicator.

    Declaration

    Swift

    func indexLessThanIndex(_ index: Int) -> Int

    Objective-C

    - (NSUInteger)indexLessThanIndex:(NSUInteger)index

    Parameters

    index

    Index being inquired about.

    Return Value

    Closest index in the index set less than index; NSNotFound when the index set contains no qualifying index.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Returns either the closest index in the index set that is less than or equal to a specific index or the not-found indicator.

    Declaration

    Swift

    func indexLessThanOrEqualToIndex(_ index: Int) -> Int

    Objective-C

    - (NSUInteger)indexLessThanOrEqualToIndex:(NSUInteger)index

    Parameters

    index

    Index being inquired about.

    Return Value

    Closest index in the index set less than or equal to index; NSNotFound when the index set contains no qualifying index.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Returns either the closest index in the index set that is greater than or equal to a specific index or the not-found indicator.

    Declaration

    Swift

    func indexGreaterThanOrEqualToIndex(_ index: Int) -> Int

    Objective-C

    - (NSUInteger)indexGreaterThanOrEqualToIndex:(NSUInteger)index

    Parameters

    index

    Index being inquired about.

    Return Value

    Closest index in the index set greater than or equal to index; NSNotFound when the index set contains no qualifying index.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Returns either the closest index in the index set that is greater than a specific index or the not-found indicator.

    Declaration

    Swift

    func indexGreaterThanIndex(_ index: Int) -> Int

    Objective-C

    - (NSUInteger)indexGreaterThanIndex:(NSUInteger)index

    Parameters

    index

    Index being inquired about.

    Return Value

    Closest index in the index set greater than index; NSNotFound when the index set contains no qualifying index.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • The index set fills an index buffer with the indexes contained both in the index set and in an index range, returning the number of indexes copied.

    Declaration

    Swift

    func getIndexes(_ indexBuffer: UnsafeMutablePointer<Int>, maxCount bufferSize: Int, inIndexRange indexRange: NSRangePointer) -> Int

    Objective-C

    - (NSUInteger)getIndexes:(NSUInteger *)indexBuffer maxCount:(NSUInteger)bufferSize inIndexRange:(NSRangePointer)indexRange

    Parameters

    indexBuffer

    Index buffer to fill.

    bufferSize

    Maximum size of indexBuffer.

    indexRange

    Index range to compare with indexes in the index set; nil represents all the indexes in the index set. Indexes in the index range and in the index set are copied to indexBuffer. On output, the range of indexes not copied to indexBuffer.

    Return Value

    Number of indexes placed in indexBuffer.

    Discussion

    You are responsible for allocating the memory required for indexBuffer and for releasing it later.

    Suppose you have an index set with contiguous indexes from 1 to 100. If you use this method to request a range of (1, 100)—which represents the set of indexes 1 through 100—and specify a buffer size of 20, this method returns 20 indexes—1 through 20—in indexBuffer and sets indexRange to (21, 80)—which represents the indexes 21 through 100.

    Use this method to retrieve entries quickly and efficiently from an index set. You can call this method repeatedly to retrieve blocks of index values and then process them. When doing so, use the return value and indexRange to determine when you have finished processing the desired indexes. When the return value is less than bufferSize, you have reached the end of the range.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

  • Executes a given Block using each object in the index set.

    Declaration

    Swift

    func enumerateIndexesUsingBlock(_ block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (void)enumerateIndexesUsingBlock:(void (^)(NSUInteger idx, BOOL *stop))block

    Parameters

    block

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    Discussion

    This method executes synchronously.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Executes a given Block over the index set’s indexes, using the specified enumeration options.

    Declaration

    Swift

    func enumerateIndexesWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (void)enumerateIndexesWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx, BOOL *stop))block

    Parameters

    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). See NSEnumerationOptions for the supported values.

    block

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    Discussion

    This method executes synchronously.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • Executes a given Block using the indexes in the specified range, using the specified enumeration options.

    Declaration

    Swift

    func enumerateIndexesInRange(_ range: NSRange, options opts: NSEnumerationOptions, usingBlock block: ((Int, UnsafeMutablePointer<ObjCBool>) -> Void)?)

    Objective-C

    - (void)enumerateIndexesInRange:(NSRange)range options:(NSEnumerationOptions)opts usingBlock:(void (^)(NSUInteger idx, BOOL *stop))block

    Parameters

    range

    The range to enumerate.

    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). See NSEnumerationOptions for the supported values.

    block

    The Block to apply to elements in the set.

    The Block takes two arguments:

    idx

    The index of the object.

    stop

    A reference to a Boolean value. The block can set the value to YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

    Discussion

    This method executes synchronously.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.