我已经使用此代码在NSMutableDictionary中填充了一个uitableview来填充我的字典:
-(NSMutableDictionary *)createDictionaryForSectionIndex:(NSArray *)array withSubtitle:(NSArray *)subtitle
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for (char firstChar = 'a'; firstChar <= 'z'; firstChar++)
{
NSString *firstCharacter = [NSString stringWithFormat:@"%c", firstChar];
NSArray *content = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[cd] %@", firstCharacter]];
NSMutableArray *mutableContent = [NSMutableArray arrayWithArray:content];
if ([mutableContent count] > 0)
{
NSString *key = [firstCharacter uppercaseString];
[dict setObject:mutableContent forKey:key];
NSLog(@"%@: %lu", key, (unsigned long)[mutableContent count]);
}
NSLog(@"mutable content: %@", mutableContent);
}
return dict;
}
来自此来源:https://stackoverflow.com/a/13279408/1042801
我试图为每个输出的键/值添加另一个键/值。说出我的想法有点困难,所以这里有一些我认为需要的例子:
key => 'A'
object => {"Aardvark"
object => {"mammal"}
, "Ape"
object => {"mammal"}
, "Aquaman"
object => {"superhero"}
}
//etc...
我的表视图应该能够访问其上方每个对象的那些键,以用作表视图中单元格的详细文本标签。如果我想要完成的事情没有任何意义,我很抱歉,字典在我的剧目中还没有完全彰显。