You can find out how many key-object (key-value) pairs there are like so:
NSArray * allKeys = [mutableDictionary allKeys];
NSLog(@"Count : %d", [allKeys count]);
EDIT
Upon looking through the dictionary documentation, NSDictionary
's count
method (or property) should work as well. I think you may have been receiving 0 count because the dictionary was empty or nil. I offered my solution because I tend to care more about enumerating the keys than counting the entries directly.
Please consider the fact that you fixed the issue somewhere else.
• By actually populating the dictionary
or
• By fixing a bug where mutableDictionary was somehow nil
I run this test code and get the commented output
NSMutableDictionary * countDict = [NSMutableDictionary dictionaryWithObject:@"test" forKey:@"test"];
[countDict setObject:@"foo" forKey:@"bar"];
NSLog(@"test count %d", countDict.count); //test count 2
countDict = nil;
NSLog(@"test count %d", countDict.count); //test count 0