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 a index set.
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.
Each index value can appear only once in the index set. This is an important concept to understand and is why you would not use index sets to store an arbitrary collection of integer values. To illustrate how this works, if you created an NSIndexSet object with the values 4, 5, 2, and 5, the resulting set would only have the values 4, 5, and 2 in it. Because index values are always maintained in sorted order, the actual order of the values when you created the set would be 2, 4, and then 5.
In most cases, using an index set is more efficient than storing a collection of individual integers. Internally, the NSIndexSet class represents indexes using ranges. For maximum performance and efficiency, overlapping ranges in an index set are automatically coalesced—that is, ranges merge rather than overlap. Thus, the more contiguous the indexes in the set, the fewer ranges are required to specify those indexes.
The designated initializers of the NSIndexSet class are: initWithIndexesInRange: and initWithIndexSet:.
You must not subclass the NSIndexSet class.
The mutable subclass of NSIndexSet is NSMutableIndexSet.
====================================================================
The NSIndexPath class represents the path to a specific node in a tree of nested array collections. This path is known as an index path.
Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node. For example, the index path 1.4.3.2 specifies the path shown in Figure 1.
====================================================================
NSRange
A structure used to describe a portion of a series—such as characters in a string or objects in an NSArray object.
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
Fields
location
The start index (0 is the first, as in C arrays).
length
The number of items in the range (can be 0).
======================================================
NSIndexSet 用來讓你從某個 data structure 里面提取一部分東西出來成為一個新的東西。
比如你有一個 NSArray, 里面是
(one, two, three, four, five)
然后你造了個 indexSet 的內容是 1,2,3,5
然后你把它套到那個 array 上,就是 (one, two,three,five)
它是這么說的,具體看看apple的文檔
======================================================
NSIndexPath 讓你精確指定一個樹結構 data structure 里面的某個節點的數據
比如你有一個 NSArray, 里面很多節點,每個節點又是一個 NSArray,每個節點的這個里面又是一個NSArray,然后下面又是一個 NSArray
這樣簡單說起來,你有一個四層的 NSarray ,每層下面都有好多個 NSArray。
然后你造一個 NSIndexPath 1.3.4.2
你就可以拿它訪問 第一層的第三個節點之下的第四個節點的第二個節點的數據
它是這么說的,具體看看apple的文檔
======================================================
NSRange 就是 從 x 到 y
比如 3 到 6
比如你有一個 NSString, 內容是 "go home and eat"
你就可以拿這個range截取這個 NSString, 3-6 就是 “home”
它是這么說的,具體看看apple的文檔