ios - Checking If One Array Contains An Object of Another Array In Objective C -


i using below function check whether if object in array present in array. if object not present, add object new array, or else object not included in new array instantiated.

+ (nsmutablearray *)loadungroupedspeakerlist {     nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults];      nsmutablearray *speakerlist = [[nsmutablearray alloc] init];     nsarray *speakeridlist = [userdefaults objectforkey:data_speaker_idlist];     nsarray *speakeridlistgrouped = [userdefaults objectforkey:data_speaker_idlist_grouped];      //**** checking contents of speakeridlistgrouped ****//     for(nsstring *speakerid in speakeridlistgrouped)     {         nslog(@"flowcheck~ loadungroupedspeakerlist check content:%@", speakerid);     }      for(nsstring *speakerid in speakeridlist)     {         if(![speakeridlistgrouped containsobject:speakerid])         {             nslog(@"flowcheck~ loadungroupedspeakerlist: speakerid: %@", speakerid);              nsdictionary *speakerdict = [userdefaults dictionaryforkey:[nsstring stringwithformat:@"%@%@", data_speaker_dict, speakerid]];              [speakerlist addobject:speakerdict];         }     }      return speakerlist; } 

in above code, speakerlist contains speakerids. while speakeridlistgrouped contains speakerids used in group. function needs eliminate speakerids used in group did in way above code.

my problem: when run code, notice if speakeridlistgrouped contains object in speakeridlist, these 2 lines still executed

nsdictionary *speakerdict = [userdefaults dictionaryforkey:[nsstring stringwithformat:@"%@%@", data_speaker_dict, speakerid]];  [speakerlist addobject:speakerdict]; 

whereas understand, should not happen. because allowed them executed if speakeridlist not contain object.

this log when execute code:

2015-06-15 19:31:24.849 soulbeats[1936:433953] flowcheck~ loadungroupedspeakerlist check content:72243140485836704 2015-06-15 19:31:24.850 soulbeats[1936:433953] flowcheck~ loadungroupedspeakerlist check content:7782687177520836128 2015-06-15 19:31:24.850 soulbeats[1936:433953] flowcheck~ loadungroupedspeakerlist: speakerid: 72243140485836704 2015-06-15 19:31:24.851 soulbeats[1936:433953] flowcheck~ loadungroupedspeakerlist: speakerid: 7782687177520836128 

as can seen, speakeridlistgrouped does contain 2 objects. however, when tried replacing string inside lower loop hardcoding 1 of objects printed on log, 72243140485836704. function works properly, mean didn't execute 2 lines showed before.

i confused. difference between string hardcoded , 1 obtained array? contents same.

many thanks!

i did same thing working fine...

nsmutablearray *speakerlist = [[nsmutablearray alloc] init]; nsarray *speakeridlist = @[@"a",@"b",@"c",@"d",@"e"]; nsarray *speakeridlistgrouped =@[@"a",@"b",@"f",@"g",@"h"]; for(nsstring *speakerid in speakeridlistgrouped) {     nslog(@"%@", speakerid); }  for(nsstring *speakerid in speakeridlist) {     if(![speakeridlistgrouped containsobject:speakerid])     {         nslog(@"flowcheck~ loadungroupedspeakerlist: speakerid: %@", speakerid);            [speakerlist addobject:speakerid];     } } 

there might issue objects inside array....


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -