0

I am working for UIImage storing to NSMutableArray. How i can sort it with the UIImage because it's not storing any parameter or for-key by which i can sort using any comparator code.

I am working to store UIImage from image picker controller. After storing numbers of images to NSMutableArray. After that i need to sort My mutable to Last In First out(LIFO). It's currently working as First In First Out(FIFO) or descending. We are storing images to array as follow:

NSMutableArray *images = [NSMutableArray arrayWithCapacity:[info count]];

    for (NSDictionary *dict in info) {

        UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage];
        [images addObject:image];

    }


    [_currentData addObjectsFromArray:images];

After Storing i am not able to Sort Last added object to First display in image view. Following code Crashes for me:

NSSortDescriptor *desc = [NSSortDescriptor sortDescriptorWithKey:@"" ascending:NO];
    [_currentData sortUsingDescriptors:@[desc]];

My _currentData is main NSMutableArray which i am using to display in the table view after shorting.

Please help me For sorting UIImage stored NSMutableArray for LAST IN FIRST OUT(LIFO) descending order.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Hrushikesh Betai
  • 2,227
  • 5
  • 33
  • 63

2 Answers2

1

This question is basically the same: How can I reverse a NSArray in Objective-C?

You might want to try this:

NSArray * copy = [[array reverseObjectEnumerator] allObjects];

It is also worth noting that iterating over a dictionary does not guarantee a certain order.

Community
  • 1
  • 1
Felix Lamouroux
  • 7,414
  • 29
  • 46
0

Simple solution is fetch data using reverse for loop.

for (int i = arr.count-1; i >= 0; i--) {
    UIImage *img = [arr objectAtIndex:i];
}

get images from your NSMutableArray using reverse loop.

DharaParekh
  • 1,730
  • 1
  • 10
  • 17