xcode - Can NSRange variable contain multiple ranges? -


Is it possible that there are several categories in the NSR variable? Some NSRange = [NSMakeRange (0, 2), NSMakeRange (10, 1), ...]

or on

  Is there another varaible type for more than one category?   

Another varaible type for many

or may not be the ranges?

Yes, Ns (convertible) IndexSet stores a collection of unsigned integers in the form of sequence of Indexes (unique) dates. Example: Create a variable index set and add both series and one index:

  Go to indexSet = NSMutableIndexSet () indexSet.addIndexesInRange (NSMakeRange (0, 2) indexSet .addIndexesInRange (NSMakeRange (10, 3) indexSet.addIndex (5) println (indexSet) // & LT; NSMutableIndexSet: 0x10050a510 & gt; [Number of indexes: 6 (ranges in 3), indexed: (0-1 5 10-12)]  

Specify all indexes:

  IndexSet.enumerateIndexesUsingBlock {(index, stop) - & gt; Zero (index) in println // output: 0 to 5 to 10 11 12  

Calculate all the boundaries:

  indexSet.enumerateRangesUsingBlock {( Range, stop) - & gt; Println in zero (range)} // output: (0,2) (5,1) (10,3)  

test subscription:

  If indexSet.containsIndex (11) {// ...}  

but note that NSIndexSet represent the group , i.e. There are no duplicate elements, and the sequence of elements does not matter, it may or may not be useful depending on your needs. Example:

  Go to indexSet = NSMutableIndexSet () indexSet.addIndexesInRange (NSMakeRange (0, 4)) indexSet.addIndexesInRange (NSMakeRange (2, 4)) indexSet.enumerateRangesUsingBlock {(range, off Cry) - & gt; Zero (range)} / output in println: (0,6)  

Comments