objective c - iOS, Sort allKeys of NSDictionary -
<-- why have been down voted? @ least comment reasoning
i have incoming json array details consecutive & non-consecutive date periods.
an example:
(please note, root index values example clarity. real data associative key-value)
[0] => '01/01/2015 - 05/01/2015' : ['01/01/2015', '02/01/2015', '03/01/2015', '04/01/2015', '05/01/2015'], [1] => '01/02/2015 - 05/02/2015' : ['01/02/2015', '02/02/2015', '03/02/2015', '04/02/2015', '05/02/2015'], [2] => '25/03/2015': '25/03/2015', [3] => '01/04/2015': '01/04/2015'
my final intention display each associative key in uitableview
, consecutive date cells (indexes [0]
& [1]
in example), on select segue uitableview
listing each individual date of consecutive block. non-consecutive date cells, (index [2]
& [3]
in example) not selectable user there nothing more see. savvy?
my issue import json array both nsarray
, & nsdictionary
. (the reader should aware arrays ordered, dictionaries not)
nsarray
of imported data structured true. issue have no way of displaying keys in first uitableview
, 2nd uitableview
can populated relating value.
i take nsarray
of allkeys
of nsdictionary
, gives me structured array of keys of un-structured dictionary. can use display in first uitableview
, representation of data structure not true imported structure. jumbled & different each time.
my question how hell do this? should imagine question may not specific enough.... so, how sort allkeys
array of dictionary in date order?
if thinking, "well easy! sort using descriptor",
like one...?
nssortdescriptor *descriptor=[[nssortdescriptor alloc] initwithkey:@"self" ascending:no]; nsarray *descriptors=[nsarray arraywithobject: descriptor]; nsarray *reverseorder=[self.datekeys sortedarrayusingdescriptors:descriptors];
sadly, easy. works fine non-consecutive date keys, or single dates, have consecutive date keys, '01/01/2015 - 05/01/2015'
fails. overall nsarray
closer true imported data structure, not close enough
you map response nsarray
, each item nsdictionary
key (the range) , either nsarray
of values (the dates) or nsstring
(single date).
example:
nsarray *data = @[ @{ @"01/01/2015 - 05/01/2015" : @[ @"01/01/2015", @"02/01/2015", @"03/01/2015", @"04/01/2015", @"05/01/2015" ] }, @{ @"25/03/2015" : @"25/03/2015" } ];
then, can fill first uitableview
the main array, each item in array, dictionary key.
nsmutablearray *table1data = [[nsmutablearray alloc] initwithcapacity:data.count]; (nsdictionary *daterange in data) { [table1data addobject:[[daterange allkeys] firstobject]]; }
and second uitableview
filled value of dictionary (array of dates) of selected item in main array, when value nsarray
:
id table2data = [[data[selectedindex] allvalues] firstobject]; if ([table2data iskindofclass:[nsarray class]]) { // navigate second view, passing table2data second table view data. // cast table2data nsarray if needed. } else { // not navigate second view }
Comments
Post a Comment