1.添加元素的时候,先取出数组,再向数组中添加元素:
- (void)addPeason:(AddressPeason *)peason
{
if (![[peason getName] isEqualToString:nil]) {
for (NSString *string in [_peasonDictionary allKeys]) {
if ([[[peason getName] substringToIndex:1] isEqualToString:string]) {
[[_peasonDictionary valueForKey:string] addObject:peason];
}
}
}
}
2.输出元素时,亦先取出数组,再遍历数组
- (void)show
{
for (NSString *string in [_peasonDictionary allKeys]) {
NSLog(@"字母:%@", string);
NSArray *array = [_peasonDictionary valueForKey:string];
for (AddressPeason *peason in array) {
[peason showInfo];
}
}
}
原文地址:http://www.cnblogs.com/hetty/p/3698860.html