NSSortdescriptor, finding the path to the key I wish to use for sorting.

Posted by RickiG on Stack Overflow See other posts from Stack Overflow or by RickiG
Published on 2010-05-19T14:28:03Z Indexed on 2010/05/19 14:30 UTC
Read the original article Hit count: 212

Hi

I am using an NSSortdescriptor to sort a collection of NSArrays, I then came across a case where the particular NSArray to be sorted contains an NSDictionary who contains an NSDictionary. I would like to sort from the string paired with a key in the last dictionary.

This is how I would reference the string:

NSDictionary *productDict = [MyArray objectAtIndex:index];
NSString *dealerName = [[productDict objectForKey:@"dealer"] objectForKey:@"name"];

How would I use the dealerName in my NSSortdescriptor to sort the array?

NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:/* ? */  ascending:YES];
sortedDealerArray = [value sortedArrayUsingDescriptors:sortDesc];
[sortDesc release];

Hope someone could help me a bit with how I go about sorting according to keys inside objects inside other objects:)

Thank you.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nssortdescriptor