views:

57

answers:

2

Just curious if there is a way to find the number of keys in a NSMutableDictionary? Also is there a way to access each key in turn and find its value, or do I need to access the data manually via the predefined keys?

(i.e.)

myTown  = [cryo objectForKey: @"town"];
myZip   = [cryo objectForKey: @"HT6 4HT"];
myEmail = [cryo objectForKey: @"[email protected]"];

I guess I am thinking using a wildcard or something for the key?

gary

A: 
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
NSLog(@"%d", [[dict allKeys] count]);

[dict allKeys] gives you the list of all the current keys.

luvieere
+7  A: 

-[NSMutableDictionary count]

Barry Wark
thanks, should have known, I am starting to see a pattern with this language :)
fuzzygoat
Yes, the Cocoa frameworks are very well designed. You should expect that patterns you discover in one location will work in other parts of the framework. In the case of collection classes, the common API is consistent, even though there are no abstract base classes or interfaces for the collection API as in other languages/frameworks.
Barry Wark