user773578
user773578

Reputation: 1161

Resorting an NSMutableArray

How does one resort an NSMutableArray using an index?

I would like to take an index e.g. 9 and everything up to 9, 0 - 8, needs to be put at the end of the array so the array would look something like this.

9, 10, 11, 12, 13, 0, 1, 2, 3, 4, 5, 6, 7, 8

in terms of the positioning.

How is this done in objective C?

Thanks

Upvotes: 0

Views: 158

Answers (2)

AliSoftware
AliSoftware

Reputation: 32681

If you just want to move objets at index 0-8 to the end of the array, that's quite easy:

NSRange r = NSMakeRange(0,9); // the range of items to push to the end
// extract the first 9 items in the array to keep them around
NSArray* first9 = [yourArray subarrayWithRange:r];
// remove them from the original NSMutableArray
[yourArray removeObjectsInRange:r];
// add them back to the end
[yourArray addObjectsFromArray:first9];

Upvotes: 1

Hot Licks
Hot Licks

Reputation: 47699

NSMutableArray implements all the sort functions that NSArray does.

Upvotes: 0

Related Questions