suse
suse

Reputation: 10563

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

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

Upvotes: 20

Views: 52772

Answers (3)

Ravi Kumar
Ravi Kumar

Reputation: 1366

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

Upvotes: 0

dreamlax
dreamlax

Reputation: 95335

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

Upvotes: 44

andyvn22
andyvn22

Reputation: 14824

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
}

Upvotes: 6

Related Questions