// 轉(zhuǎn)換為首字母分組
-(NSArray*)setFilterData:(NSArray *)filterData{
NSMutableArray *arrM = [NSMutableArray array];
for (int i = 'A'; i <= 'Z'; i++) {
NSString *dicKey = [NSString stringWithFormat:@"%c",i];
// 創(chuàng)建可變數(shù)組
NSMutableArray *PYarrM = [NSMutableArray array];
// 循環(huán)遍歷當(dāng)前的key 有沒有對(duì)應(yīng)的模型添加到數(shù)組
for (XKProvinceModel *model in filterData) {
// 下面的方法需要導(dǎo)入轉(zhuǎn)拼音的第三方 github搜索: ZYPinYinSearchLib
NSString *hearPY = [PinYinForObjc chineseConvertToPinYinHeadOne:model.provinceName];
if ([dicKey isEqualToString:hearPY]) {
[PYarrM addObject:model];
}
}
//判斷數(shù)組不為空 添加
if (PYarrM.count) {
NSDictionary * dict = @{dicKey : PYarrM};
[arrM addObject:dict];
}
}
return arrM.copy;
}