ios - NSDictionary find index of value of a key -
ios - NSDictionary find index of value of a key -
so have 2 dictionaries structured such:
{ version: "1.0", timestamp: 1123, data: [ { foo: "0.0026", bar: 548, }, { foo: "0.0065", bar: 341, }, ], revision: 1234 } and such
{ version: "1.0", timestamp: 1123, data: [ { foo74: "0.0026", bar: 340, }, { foo74: "0.0378", bar: 548, }, ], revision: 2345 } these loaded in asynchronously 2 separate api calls , uitableview reloaded. in each uitableviewcell need match barvalues display relevant info in each cell. example: @ index 0 of uitableview contain bar: 548 , foo: "0.0026" however, in same cell need include value of foo74 in case "0.0378". meaning have go through sec info set , find index @ bar equal 548.
i trying figure way within of cellforrowatindexpath without having iterate through each 1 of sec info entries each 1 of first (resulting in o(n^2) runtime).
i have tried allkeysforobject passing value of 548 sec info set, , doesn't seem homecoming anything.
i considered sorting them before hand, give me improve runtime.
i looking avoid me having this:
for (int = 0; < [[dict2 objectforkey:@"data"] count]; i++) { if(dict1[@"data"][indexpath.row][@"bar"] == dict2[@"data"][i][@"bar"]) { nslog(@"found"); } }
before table view reloaded, should index info in dict2 nsdictionary key value of "bar" , value info want (in case value of "foo74").
inside cellforrowatindexpath method, phone call indexdict[dict1[@"data"][indexpath.row][@"bar"]] find data. if value nil, means not found.
the loop indexing takes o(n) runtime , each phone call find info takes o(1) runtime.
ios objective-c uitableview nsdictionary
Comments
Post a Comment