如何在Objective-C中获取字典中每个键的值?

sus*_*use 20 objective-c nsmutabledictionary

我正在维护一个NSMutableDictionary包含键和值对的东西.现在我需要对其中的每个值执行一些操作.如何从字典中检索值.

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

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

如何进行?请帮助

dre*_*lax 44

for (id key in dictobj)
{
    id value = [dictobj objectForKey:key];
    [value doSomething];
}
Run Code Online (Sandbox Code Playgroud)


and*_*n22 6

我不完全清楚你的问题是什么,但你可能正在寻找:

for (id currentValue in [dictobj allValues])
{
    //stuff with currentValue
}
Run Code Online (Sandbox Code Playgroud)