Objective-c best data structure sortable of string and bool -


i need store list of strings items in tableview , for each string need store bool value.. use nsdictionary how can sort list of strings alphabetically (using selector) , sort @ same time bool values?

i know exists methods sortusingselector or usingcomparator, in nsdictionary can sort keys values need reverse..

can me, maybe using data structure?

i recommend following data structure:

use nsarray of nsdictionaries (make property):

self.array = @[@{@"string": @"zusuuuuu", @"bool": @0}, // not creative ;-) wanted unsorted example                @{@"string": @"yourcontent", @"bool": @0},                @{@"string": @"yourothercontent", @"bool": @1}]; 

you can sort this:

self.array = [self.array sortedarrayusingcomparator:^nscomparisonresult(nsdictionary *adictionary, nsdictionary *anotherdictionary) {     return [adictionary[@"string"] compare:anotherdictionary[@"string"]]; }]; 

if want populate uitableview following:

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return self.array.count; //if want them in 1 section, easiest case }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     // ...     // initialization of cell     // ...      cell.yourlabel.text = self.array[indexpath.row][@"string"];     cell.yourswitch.on = ((nsnumber *)self.array[indexpath.row][@"bool"]).boolvalue;     return cell; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -