How to get the value for each key in dictionary in Objective-C?

寵の児 提交于 2020-01-01 23:57:31

问题


I'm maintaining a NSMutableDictionary which holds key and value pair.Now i need to perform some operation for each value in it.How to retrive value from dictionary.

// this is NSMutableDIctionary 
NSMutableDictionary *dictobj = [[NSMutableDictionary alloc]init];
 // in methodA

-(void)methodA
{
   //get the value for each key and peform an operation on it.
}

How to proceed? plz help


回答1:


for (id key in dictobj)
{
    id value = [dictobj objectForKey:key];
    [value doSomething];
}



回答2:


I'm not entirely clear what your question is asking, but you might be looking for:

for (id currentValue in [dictobj allValues])
{
    //stuff with currentValue
}



回答3:


NSArray *array = [viewControllers allValues];
for (int i = 0; i<array.count; i++) {        
    MenuListingVC *vc = array[i];
    [vc tableDataReload];
}


来源:https://stackoverflow.com/questions/2286186/how-to-get-the-value-for-each-key-in-dictionary-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!