I have an array of dictionaries "_displayedObjects" where one of the keys "receiptDate" contains the string representation of date values like "12/23/11", "3/5/11", etc.
I need to sort "_displayedObjects" on the key "receiptDate" by the actual Date but still return a sorted array of dictionaries where the "receiptDate" key values remain as strings.
The code below sorts the "receiptDate" key as strings. How would I sort this by Date? Would I create a copy of the array where I have converted all of the "receiptDate" key values to NSDate values, sort it by Date and then convert the values back to strings? Not exactly sure how to approach this.
Code:
NSSortDescriptor * sortDesc1 = [[NSSortDescriptor alloc] initWithKey:(@"receiptDate") ascending:YES];
NSSortDescriptor * sortDesc2 = [[NSSortDescriptor alloc] initWithKey:(@"title") ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[_displayedObjects sortUsingDescriptors:[NSArray arrayWithObjects:sortDesc1, sortDesc2, nil]];
[self setTitle:@"Sorted by Date"];
Thanks in advance