ios - NSPredicate to fetch dictionary from array of arrays -


from following array want fetch dictionary message_id = 1. want indexpath of cell message_id == 1.

<__nsarraym 0x17d918d0>( <__nsarraym 0x17faa070>( {     chatstatus = sent;     date = "feb 05, 2016";     = "";     height = "17.000000";     isoutgoing = yes;     "message_id" = "1";     time = "02:39 pm";     = "";     width = "95.000000"; }, {     chatstatus = sent;     date = "feb 05, 2016";     = "";     height = "17.000000";     isoutgoing = yes;     "message_id" = "2";     time = "02:39 pm";     = "";     width = "95.000000"; }, )  ) 

i think should around nsarray's method

-[nsarray indexesofobjectspassingtest:^bool(id  _nonnull obj, nsuinteger idx, bool * _nonnull stop)] 

by doing :

        nsmutablearray *indexpaths = [nsmutablearray array];      [myarray enumerateobjectsusingblock:^(id  _nonnull obj, nsuinteger firstindex, bool * _nonnull stop) {          nsarray *messages = (nsarray*)obj;          nsindexset *indexes = [messages indexesofobjectspassingtest:^bool(id  _nonnull obj, nsuinteger idx, bool * _nonnull stop) {              nsdictionary *message = (nsdictionary*)obj;              if (message.message_id == 1) {                 return yes;             }             return no;          }];          [indexes enumerateindexesusingblock:^(nsuinteger idx, bool * _nonnull stop) {              [indexpaths addobject:[nsindexpath indexpathforrow:idx insection:firstindex]];          }];      })]; 

it's seems bit tricky, , did think improve it. idea enumerate through first array, , use "indexesofobjectspassingtest" indexes matching objects. , , indexpaths going through enumeration of nsindexset object :)

i think recursively, won't limited depth of arrays is, here, 2 :/

hope helped \o bilkix.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -