Hi guys,
my question is: I have a dictionary with one object for each character of the alphabet. Within those objects, there are all values for a specific character.
Example:
alphabetDictionary
a
apple
alien
b
balloon
ball
I now want to count all entries within this dictionary:
apple
alien
balloon
ball
-> 4
Using this sourcecode only counts the objects (a, b, etc)
NSString *counter = [NSString stringWithFormat:@"Entries (%d)", alphabetDictionary.count];
So how do I get all entries and not the objects a,b,etc?
EDIT 1: In the viewDidLoad Method I have:
//Initialize the array.
charDict = [[NSMutableDictionary alloc] init];
alphabetArray = [[NSMutableArray alloc] init];
if ([charSpecialArray count] > 0) {
//Set object for this character within the dictionary
[charDict setObject:charSpecialArray forKey:@"#"];
//fill the alphabetArray with an index value, if this char exists at all
[alphabetArray addObject:@"#"];
}
if ([charAArray count] > 0) {
[charDict setObject:charAArray forKey:@"A"];
[alphabetArray addObject:@"A"];
}
etc.. for each character
followed by:
totalCounter = 0;
//Count all keys within the Dictionary
for (id objectKey in charDict.allKeys) {
totalCounter += [[charDict objectForKey:objectKey] count];
NSLog(@"Anzahl: %d", totalCounter);
}
NSString *counter = [NSString stringWithFormat:@"TXNs (%d)", totalCounter];
self.title = counter;
the results are looking much too high:
- Character H has 33 entries
- the count of H characters results in: 132
- m characters: 1587
- m characters count: 6348
Any ideas why those counts are this high?