Specific order NSMutableArray [closed]
Good day.
I have an NSMutableArray that contains references to objects. I need to rearrange the array so that each would-scanned object becomes the last in the array.
For example:
The array has three links to three pictures. Member and one looke开发者_高级运维d out, we save before exiting the index of images viewed
The user has gone back into the program and he has shown a different picture, the one that went beyond that which he looked
A kind of carousel:)
Schematically as follows:
{Store} {look last} {when reload}
[0], [1], [2] -----> [1] ------> [2], [0], [1]
[2], [0], [1] -----> [2] ------> [0], [1], [2]
i add object in cycle
for (int i = 0; i < [self.myStorage count]; i++) {
NSManagedObject *obj = [self.myStorage objectAtIndex:i];
[self.myArray addObject: obj];
}
and reorder
int last = {get last from core data storage here}
for (int i = 0; i < [self.myArray count]; i++) {
if(i != last) {
[self.myArray exchangeObjectAtIndex:i withObjectAtIndex:0];
}
}
That is right ?
This is a total guess at what you're asking, but if you want to reorder the array by moving the object selected by the user to the front, then you can simply use the NSMutableArray
methods removeObjectAtIndex:
and insertObject:atIndex:
. I'll elaborate further if you do.
精彩评论