0

I have two separate dictionaries. First one has letter's equivalent icon names, and the second one has the number of frames for icon. The definition is as follows:

NSDictionary *alphabet = [[NSDictionary alloc] initWithObjectsAndKeys: @"A", @"A", @"B", @"B", @"C", @"C", @"Ç", @"CC", @"D", @"D", @"E", @"E", @"F", @"F", @"G", @"G", @"Ğ", @"GG", @"H", @"H", @"I", @"I", @"İ", @"II", @"J", @"J", @"K", @"K", @"L", @"L", @"M", @"M", @"N", @"N", @"O", @"O", @"Ö", @"OO", @"P", @"P", @"R", @"R", @"S", @"S", @"Ş", @"SS", @"Q", @"Q", @"T", @"T", @"U", @"U", @"Ü", @"UU", @"V", @"V", @"W", @"W", @"X", @"X", @"Y", @"Y", @"Z", @"Z", @" ", @"EMPTY", nil];
NSDictionary *icons = [[NSDictionary alloc] initWithObjectsAndKeys: @"A", @"4", @"B", @"3", @"C", @"1", @"CC", @"5", @"D", @"4", @"E", @"4", @"F", @"4", @"G", @"4", @"GG", @"7", @"H", @"4", @"I", @"1", @"II", @"6", @"J", @"6", @"K", @"4", @"L", @"1", @"M", @"4", @"N", @"4", @"O", @"1", @"OO", @"6", @"P", @"4", @"Q", @"1", @"R", @"4", @"S", @"4", @"SS", @"6", @"T", @"4", @"U", @"1", @"UU", @"6", @"V", @"1", @"W", @"1", @"X", @"1", @"Y", @"4", @"Z", @"4", @"EMPTY", @"0", nil];

I get a word, then for each letter try to get icon name from alphabet and number of frames from icons. However, icons always return nil. I tried NSNumber for icons, but it doesn't work.

for (int i = 0; i < textLength; i++) {
        NSString * iconLetter = [icons objectForKey: [heardText substringWithRange:NSMakeRange(i, 1)]];
        int iconFrame = [[alphabet objectForKey: iconLetter] intValue];
}
4

1 回答 1

4

Your value and key pairs for icon are in wrong position. It should be "value, forKey" pattern, or "1", "A", ....

于 2012-04-30T14:35:47.640 回答