// 转换为首字母分组
-(NSArray*)setFilterData:(NSArray *)filterData{
NSMutableArray *arrM = [NSMutableArray array];
for (int i = 'A'; i <= 'Z'; i++) {
NSString *dicKey = [NSString stringWithFormat:@"%c",i];
// 创建可变数组
NSMutableArray *PYarrM = [NSMutableArray array];
// 循环遍历当前的key 有没有对应的模型添加到数组
for (XKProvinceModel *model in filterData) {
// 下面的方法需要导入转拼音的第三方 github搜索: ZYPinYinSearchLib
NSString *hearPY = [PinYinForObjc chineseConvertToPinYinHeadOne:model.provinceName];
if ([dicKey isEqualToString:hearPY]) {
[PYarrM addObject:model];
}
}
//判断数组不为空 添加
if (PYarrM.count) {
NSDictionary * dict = @{dicKey : PYarrM};
[arrM addObject:dict];
}
}
return arrM.copy;
}