Adding Indexes

- addIndex:

Adds an index to the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet addIndex:10];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:01:39.425 iOS-Tutorial[1885:a0b] [number of indexes: 5 (in 2 ranges), indexes: (0-3 10)]
		

- addIndexes:

Adds the indexes in an index set to the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet addIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(6, 2)]];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:02:50.351 iOS-Tutorial[1908:a0b] [number of indexes: 6 (in 2 ranges), indexes: (0-3 6-7)]
		

- addIndexesInRange:

Adds the indexes in an index range to the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet addIndexesInRange:NSMakeRange(6, 3)];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:03:25.912 iOS-Tutorial[1920:a0b] [number of indexes: 7 (in 2 ranges), indexes: (0-3 6-8)]
		

Removing Indexes

- removeIndex:

Removes an index from the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet removeIndex:2];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:03:59.871 iOS-Tutorial[1933:a0b] [number of indexes: 3 (in 2 ranges), indexes: (0-1 3)]
		

- removeIndexes:

Removes the indexes in an index set from the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet removeIndexes:[NSIndexSet indexSetWithIndex:2]];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:04:45.029 iOS-Tutorial[1945:a0b] [number of indexes: 3 (in 2 ranges), indexes: (0-1 3)]
		

- removeAllIndexes

Removes the receiver’s indexes.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet removeAllIndexes];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:05:12.831 iOS-Tutorial[1957:a0b] (no indexes)
		

- removeIndexesInRange:

Removes the indexes in an index range from the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet removeIndexesInRange:NSMakeRange(2, 2)];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:05:40.643 iOS-Tutorial[1969:a0b] [number of indexes: 2 (in 1 ranges), indexes: (0-1)]
		

Shifting Index Groups

- shiftIndexesStartingAtIndex:by:

Shifts a group of indexes to the left or the right within the receiver.

Example

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)];
[indexSet shiftIndexesStartingAtIndex:2 by:3];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 20:06:24.852 iOS-Tutorial[1986:a0b] [number of indexes: 4 (in 2 ranges), indexes: (0-1 5-6)]
		

Advertisements