An object representing an immutable collection of unique integer values that bridges to Index
; use NSIndex
when you need reference semantics or other Foundation-specific behavior.
SDKs
- iOS 2.0+
- macOS 10.3+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
class NSIndexSet : NSObject
Overview
The NSIndex
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 .. NSNot
.
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 NSIndex
class are: init
, init(indexes
, and init(index
.
You must not subclass the NSIndex
class.
The mutable subclass of NSIndex
is NSMutable
.
Important
The Swift overlay to the Foundation framework provides the Index
structure, which bridges to the NSIndex
class and its mutable subclass, NSMutable
. For more information about value types, see Working with Cocoa Frameworks in Using Swift with Cocoa and Objective-C (Swift 4.1).