字典value为数组
时间:2014-04-29 11:22:45
收藏:0
阅读:535
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];
}
}
}
评论(0)