Friday, June 21, 2013

NSMutableIndexSet shiftIndexesStartingAtIndex by example in Objective C (iOS).


NSMutableIndexSet shiftIndexesStartingAtIndex by

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

- (void)shiftIndexesStartingAtIndex:(NSUInteger)startIndex by:(NSInteger)delta

Parameters of [NSMutableIndexSet shiftIndexesStartingAtIndex by]
startIndex
Head of the group of indexes to shift.
delta
Amount and direction of the shift. Positive integers shift the indexes to the right. Negative integers shift the indexes to the left.

Discussion of [NSMutableIndexSet shiftIndexesStartingAtIndex by]
The group of indexes shifted is made up by startIndex and the indexes that follow it in the set.

A left shift deletes the indexes in a range the length of delta preceding startIndex from the set.

A right shift inserts empty space in the range (startIndex,delta) in the receiver.

NSMutableIndexSet shiftIndexesStartingAtIndex by example.
- (void) rotateRowRightAtIndex:(NSUInteger)index
{
    NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(index*4, 4)];
    NSMutableArray *row = [[_values objectsAtIndexes:indexes] mutableCopy];
    [self rotateArrayRight:row];
    [_values replaceObjectsAtIndexes:indexes withObjects:row];
}

- (void) rotateColumnRightAtIndex:(NSUInteger)index
{
    NSMutableIndexSet *indexes = [_indexes0 mutableCopy];
    [indexes shiftIndexesStartingAtIndex:0 by:index];
    NSMutableArray *col = [[_values objectsAtIndexes:indexes] mutableCopy];
    [self rotateArrayRight:col];
    [_values replaceObjectsAtIndexes:indexes withObjects:col];
}

End of NSMutableIndexSet shiftIndexesStartingAtIndex by example article.