Creating Index Sets

+ indexSet

Creates an empty index set.

Example

NSIndexSet *indexSet = [NSIndexSet indexSet];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 17:50:27.844 iOS-Tutorial[904:a0b] (no indexes)
		

+ indexSetWithIndex:

Creates an index set with an index.

Example

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:3];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 17:51:02.746 iOS-Tutorial[917:a0b] [number of indexes: 1 (in 1 ranges), indexes: (3)]		

+ indexSetWithIndexesInRange:

Creates an index set with an index range.

Example

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 17:51:39.579 iOS-Tutorial[931:a0b] [number of indexes: 3 (in 1 ranges), indexes: (0-2)]
		

- init

Initializes an allocated NSIndexSet object.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]init];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 17:52:17.471 iOS-Tutorial[943:a0b] (no indexes)
		

- initWithIndex:

Initializes an allocated NSIndexSet object with an index.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:2];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 17:49:02.260 iOS-Tutorial[886:a0b] [number of indexes: 1 (in 1 ranges), indexes: (2)]		

- initWithIndexesInRange:

Initializes an allocated NSIndexSet object with an index range.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexesInRange:NSMakeRange(0, 3)];
NSLog(@"%@",indexSet)
		

Output

2014-04-12 17:53:01.428 iOS-Tutorial[955:a0b] [number of indexes: 3 (in 1 ranges), indexes: (0-2)]
		

- initWithIndexSet:

Initializes an allocated NSIndexSet object with an index set.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndex:3]];
NSLog(@"%@",indexSet);
		

Output

2014-04-12 17:53:52.745 iOS-Tutorial[969:a0b] [number of indexes: 1 (in 1 ranges), indexes: (3)]		

Querying Index Sets

- containsIndex:

Indicates whether the index set contains a specific index.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndex:3]];
NSLog(@"%d",[indexSet containsIndex:2]);
		

Output

2014-04-12 17:54:41.528 iOS-Tutorial[994:a0b] 1
		

- containsIndexes:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSLog(@"%d",[indexSet containsIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 2)]]);
		

Output

2014-04-12 17:56:01.357 iOS-Tutorial[1004:a0b] 1
		

- containsIndexesInRange:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSLog(@"%d",[indexSet containsIndexesInRange:NSMakeRange(2, 2)]);
		

Output

2014-04-12 17:56:40.526 iOS-Tutorial[1017:a0b] 1
		

- intersectsIndexesInRange:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSLog(@"%d",[indexSet intersectsIndexesInRange:NSMakeRange(2, 2)]);
		

Output

2014-04-12 17:57:15.297 iOS-Tutorial[1029:a0b] 1
		

- count

Returns the number of indexes in the index set.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSLog(@"%d",[indexSet count]);
		

Output

2014-04-12 17:57:44.024 iOS-Tutorial[1043:a0b] 4
		

- countOfIndexesInRange:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSLog(@"%d",[indexSet countOfIndexesInRange:NSMakeRange(2, 2)]);
		

Output

2014-04-12 17:58:15.643 iOS-Tutorial[1055:a0b] 2
		

Comparing Index Sets

- isEqualToIndexSet:

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

Example

NSIndexSet *indexSet1 = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSIndexSet *indexSet2 = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 4)]];
NSIndexSet *indexSet3 = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];
NSLog(@"%d",[indexSet1 isEqualToIndexSet:indexSet2]);
NSLog(@"%d",[indexSet2 isEqualToIndexSet:indexSet3]);
		

Output

2014-04-12 18:13:11.850 iOS-Tutorial[1076:a0b] 1
2014-04-12 18:13:11.851 iOS-Tutorial[1076:a0b] 0
		

Getting Indexes

- firstIndex

Returns either the first index in the index set or the not-found indicator.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]];
NSLog(@"%d",[indexSet firstIndex]);
		

Output

2014-04-12 18:14:02.747 iOS-Tutorial[1091:a0b] 2
		

- lastIndex

Returns either the last index in the index set or the not-found indicator.

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]];
NSLog(@"%d",[indexSet lastIndex]);
		

Output

2014-04-12 18:14:26.324 iOS-Tutorial[1104:a0b] 5

		

- indexLessThanIndex:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]];
NSLog(@"%d",[indexSet indexLessThanIndex:3]);
		

Output

2014-04-12 18:15:20.871 iOS-Tutorial[1117:a0b] 2
		

- indexLessThanOrEqualToIndex:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]];
NSLog(@"%d",[indexSet indexLessThanOrEqualToIndex:3]);
		

Output

2014-04-12 18:23:17.561 iOS-Tutorial[1149:a0b] 3
		

- indexGreaterThanOrEqualToIndex:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]];
NSLog(@"%d",[indexSet indexGreaterThanOrEqualToIndex:3]);
		

Output

2014-04-12 18:23:45.208 iOS-Tutorial[1164:a0b] 3
		

- indexGreaterThanIndex:

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

Example

NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndexSet:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]];
NSLog(@"%d",[indexSet indexGreaterThanIndex:3]);
		

Output

2014-04-12 18:24:25.415 iOS-Tutorial[1176:a0b] 4
		

Advertisements