ios - How to remove an object from other keys in a dictionary [Objective-C]? -


i have nsmutabledictionary follows:

{ 0 = (1,5,6); 1 = (0,2,6,7); 2 = (1,7,8); 5 = (0,6,10,11); 6 =  (0,1,5,7,11,12)};  

in format of {nsnumber:nsmutablearray}

i want remove every 0 there in every key or keys values of '0'. way it?

the expected outcome is:

{ 0 = (1,5,6); 1 = (2,6,7); 2 = (1,7,8); 5 = (6,10,11); 6 =  (1,5,7,11,12)}; 

i looking elegant solution.

use assuming nsmutablearray nsnumber array, key 0 removed in improvement

improved

nsmutabledictionary * dict = [nsmutabledictionary dictionary]; dict[@0] = [nsmutablearray arraywithobjects:@0,@10, nil]; dict[@1] = [nsmutablearray arraywithobjects:@0,@10, nil]; dict[@2] = [nsmutablearray arraywithobjects:@0,@7,@10, nil];  int valuetoremove = 0; //change value need (nsnumber * key in dict.allkeys) {     if([key intvalue] == valuetoremove) {dict[key] = nil;}     dict[key] = [dict[key] filteredarrayusingpredicate:[nspredicate predicatewithformat:@"intvalue != %i",valuetoremove]]; }  nslog(@"%@",dict); 

console log

2017-07-28 02:18:21.257 arrayproblemquestion[76557:1576267] {     1 =     (         10     );      2 =     (          7,          10      ); } 

if want loop keys then

nsmutablearray * array = [nsmutablearray arraywithobjects:@1,@3,@0, nil];     (nsnumber * key in [dict.allkeys filteredarrayusingpredicate:[nspredicate predicatewithformat:@"intvalue in %@",array]]) {         nslog(@"%@",key);     } 

this loop keys contained in array

hope helps


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -