How do I scroll all objects in an NSMutableDictionary regardless of keys?
The standard way would look like this:
for(id key in myDict) { id value = [myDict objectForKey:key]; [value doStuff]; }
you can use
[myDict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) { // do something with key and obj }];
if your target OS supports blocks.
You can use [dict allValues] to get the NSArray your values. Keep in mind that it does not guarantee any order between calls.
[dict allValues]
NSArray
You do not need to assign a value to a variable. You can access it directly with myDict[key] .
myDict[key]
for(id key in myDict) { NSLog(@"Key:%@ Value:%@", key, myDict[key]); }
in quick listing
for(id key in myDictionary) { id value = [myDictionary objectForKey:key]; // do something with key and obj }
in blocks:
[myDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { // do something with key and obj }];
Another way is to use the Dicts Enumerator. Here is a sample code from Apple:
NSEnumerator *enumerator = [myDictionary objectEnumerator]; id value; while ((value = [enumerator nextObject])) { /* code that acts on the dictionary's values */ }