views:

173

answers:

1

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.

A: 

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

ilteris