NSSortdescriptor, find the path to the key I want to use for sorting

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

This is how I would like to reference the string:

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

      

How do I use dealerName

my NSSortdescriptor to sort an array?

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

      

Hopefully someone can help me a little on how I am going to sort by keys within objects within other objects :)

Thanks.

+2


a source to share


1 answer


in fact warrenM is right. You can just use keypaths. @ "dealer.name" should work above.



+2


a source







All Articles