ios - Create new Dictionary from an existing by filtering some values -


ok, here problem.

i having arrays of objects(person class) added dictionary. each contains fullname , few other properties. created dictionary loop generating keys

nsstring -stringwithformat:@"person%d" 

just ease lets dictionary looks

nsdictionary *dict=@{@"person1": @"ilena jennifer dcruz", @"person2":@"james bond", @"person3":@"skylark", @"person4":@"xan xiaa zuang ming"}; 

now, need dictionary first name of each person.

how can have that?

try one:

nsdictionary *dict=@{@"person1": @"ilena jennifer dcruz",                      @"person2":@"james bond",                      @"person3":@"skylark",                      @"person4":@"xan xiaa zuang ming"                      };  nsmutabledictionary *firstnamedict=[nsmutabledictionary new]; (nsstring *key in dict) {     [firstnamedict setobject:[dict[key]componentsseparatedbystring:@" "][0]                       forkey:key]; } nslog(@"->%@",firstnamedict); 

output:

 ->{    person1 = ilena;    person2 = james;    person3 = skylarl;    person4 = xan;   } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -