0

I want to sort an NSMutableArray by a value which is stored inside a array in the object :)

For better overview i have included the Array. I would like to sort by time (starttijd)

With the NSSortDescriptor i managed to sort by url of status but not by the time.

This is my current code for sorting:

NSSortDescriptor *sortDescriptor; sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"starttuhd" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

    sortedarray = [alleitems sortedArrayUsingDescriptors:sortDescriptors];
    NSLog(@"Sorted array: %@", sortedarray);

The array

3
  • 1
    what if an object has multiple objects inside custom_fields with different starttijd dates? what should be picked for sorting? Commented Sep 12, 2014 at 10:37
  • And what's your actual code for sorting? Commented Sep 12, 2014 at 10:43
  • There will always be only 1 starttijd Commented Sep 12, 2014 at 10:44

1 Answer 1

0

First, if there's only ever 1 starttijd in the array, then why is it an array?

Anyway, you can try this:

NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"@max.starttuhd" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
sortedarray = [alleitems sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"Sorted array: %@", sortedarray);

Basically, @max is one of the KVC collection operators. Since it resolves down to a single element from the array, it may work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.