objective c - NSMutablearray with NSDictionary with same value for key into new array -


in project have nsmutablearray * arraymatchs dictionaries objects. in dictionary have key string value coincide between dictionaries in array. there way create new array inside array objects filled dictionary same key / value?

below first array(arraymatchs):

arraymatchs (     {     "match_commentary_available" = facup;     "match_comp_id" = 1198;   <------------------------     "match_date" = "sep 09";     "match_et_score" = "";     "match_formatted_date" = "09.09.2014";     "match_ft_score" = "";     "match_ht_score" = "";     "match_id" = 1937555;     "match_localteam_id" = 19941;     "match_localteam_name" = "hartley wintney";     "match_localteam_score" = "?";     "match_season_beta" = "";     "match_static_id" = 1844143;     "match_status" = "18:30";     "match_time" = "18:30";     "match_timer" = "";     "match_venue_beta" = "";     "match_venue_city_beta" = "";     "match_venue_id_beta" = 0;     "match_visitorteam_id" = 20839;     "match_visitorteam_name" = ardley;     "match_visitorteam_score" = "?";     "match_week_beta" = ""; },     {     "match_commentary_available" = "spain_cup";     "match_comp_id" = 1397;   <-------------------------------     "match_date" = "sep 09";     "match_et_score" = "";     "match_formatted_date" = "09.09.2014";     "match_ft_score" = "";     "match_ht_score" = "";     "match_id" = 1909702;     "match_localteam_id" = 16021;     "match_localteam_name" = girona;     "match_localteam_score" = "?";     "match_season_beta" = "";     "match_static_id" = 1845426;     "match_status" = "18:00";     "match_time" = "18:00";     "match_timer" = "";     "match_venue_beta" = "";     "match_venue_city_beta" = "";     "match_venue_id_beta" = 0;     "match_visitorteam_id" = 16184;     "match_visitorteam_name" = tenerife;     "match_visitorteam_score" = "?";     "match_week_beta" = ""; },     {     "match_commentary_available" = "spain_cup";     "match_comp_id" = 1397;  <--------------------------------     "match_date" = "sep 09";     "match_et_score" = "";     "match_formatted_date" = "09.09.2014";     "match_ft_score" = "";     "match_ht_score" = "";     "match_id" = 1909694;     "match_localteam_id" = 15997;     "match_localteam_name" = alaves;     "match_localteam_score" = "?";     "match_season_beta" = "";     "match_static_id" = 1845427;     "match_status" = "20:00";     "match_time" = "20:00";     "match_timer" = "";     "match_venue_beta" = "";     "match_venue_city_beta" = "";     "match_venue_id_beta" = 0;     "match_visitorteam_id" = 16079;     "match_visitorteam_name" = osasuna;     "match_visitorteam_score" = "?";     "match_week_beta" = ""; } 

)

the new array need fill uitableview should composed arrays,in specific case, 1 dictionary first object , 2 dictionary second object.

at point number of section = newarray count

number of rows in section = [newarray object @ index:section]count

i hope clear , help

alex1982

its not efficient or pretty, idea loop array, building new 1 go. each item in original, want know if array containing id exists in new array. if does, add there. if doesn't, add (within new mutable array) answer. this...

nsmutablearray *groupedarray = [nsmutablearray array];  (nsdictionary *d in arraymatchs) {     // see if there's mathing dictionary in new array     nsmutablearray *matchinginnerarray;     (nsmutablearray *innerarray in groupedarray) {         nsdictionary *firstdictionary = innerarray[0];         nsnumber *innerid = firstdictionary[@"match_comp_id"];         if ([innerid isequaltonumber:d[@"match_comp_id"]]) {             matchinginnerarray = innerarray;             break;         }     }     if (!matchinginnerarray) {         matchinginnerarray = [nsmutablearray array];         [groupedarray addobject:matchinginnerarray];     }     [matchinginnerarray addobject:d]; }  nslog(@"%@", groupedarray); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -