ios - Sort NSDictionary as per date-wise in iphone -
i have dictionary like:
{ "2014-04-12" = ( { "can_remove" = 1; "date_created" = "12-04-2014 04:23:57"; "is_connected" = 0; name = "j j"; status = gbn; "user_id" = 94; } ); "2014-04-14" = ( { "can_remove" = 0; "date_created" = "14-04-2014 02:36:52"; "is_connected" = 0; name = abc; "user_id" = 89; } ); }
the keys of dictionary represent dates. how can sort date?
i tried this, doesn't work:
nsarray* keys = [dict allkeys]; nsarray* sortedarray = [keys sortedarrayusingcomparator:^(id a, id b) { return [a compare:b options:nsnumericsearch]; }];
use following way short according date :
nsmutablearray *dictkeys = [[dict allvalues] mutablecopy]; [dictkeys sortusingcomparator: (nscomparator)^(nsdictionary *a, nsdictionary *b) { nsstring *key1 = [a objectforkey: @"field3"]; nsstring *key2 = [b objectforkey: @"field3"]; return [key1 compare: key2]; } ]; nslog (@"dictkeys - %@",dictkeys);
Comments
Post a Comment