Вопрос

I have an NSMutableArray that has NSDictionaries in it. I found a question on SO, and am using this code to sort this NSMutableArray:

NSMutableArray

{
    data =         {
   etc... (for length)
    };
    number = 1;
},
{
    data =         {
       etc... (for length)
    };
    number = 3;
},
{
    data =         {
       etc... (for length)
    };
    number = 4;
},
{
    data =         {
       etc... (for length)
    };
    number = 2;
}

This array goes up to 80 sub Dictionaries.

NSSortDescriptor

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"number"  ascending:YES];
[NSMUTABLEARRAYVAR sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
 NSMutableArray *test;            
 test = [NSMUTABLEARRAYVAR copy];

When I NSLog "test" I get the same order as NSMUTABLEARRAYVAR???

I would appreciate any help in solving this issue, thanks!

Это было полезно?

Решение

sortedArrayUsingDescriptors does not sort the array in place. It returns a newly-sorted array.

sortUsingDescriptors does an in-place sort.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top