sortingnsarraydate-sorting

Sorting NSMutableArray by string date value within a object


There is a NSMutableArray *listOfOrders;

Which consists number of model objects.

every object has a key value "dateAdded" i want to sort listOfOrders by dateAdded in Ascending order.

for e.g // values in dictOrder will different NSDictionary *dictOrder = @{@"idValue": @"12345", @"OName" : @"Abc", @"dateAdded" : @"2012-05-18 12:03:00.0" };

NSMutableArray *listOfOrders;
MyClass *class1 = [[MyClass alloc] initWithDict:dictOrder];
[listOfOrders addObject:class1];
[listOfOrders addObject:class2];
[listOfOrders addObject:class3];
[listOfOrders addObject:class4];

i want to sort the class object by dateAdded value. pls note : dateAdded value will be in string format.


Solution

  • I haven't found any solution which sort the Objects within Array orderby value in Object's Dictionary. So i have created dateAdded of NSString type in MYClass. also assign the same date valye to dateAdded which is in dictOrder.

    now it is sorting myclass objects by using sortUsingComparator method.