Baymax0 / BMChineseSort

BMChineseSort是一个为模型、字典、字符串数组根据特定中文属性基于tableview分组优化的工具类,基于异步、多线程降低排序时间。
Other
192 stars 23 forks source link

能把同“姓”的放在一起吗 #19

Closed TomasWell closed 3 years ago

TomasWell commented 3 years ago

BMChineseSort是个很高效的库

但是对于通讯录这块 产品要求同姓的放在一起

“张a”、“赵b”、“张c”、“赵e”、“赵a” BMChineseSort排序为: “张a”、“赵b”、“张c”、“赵e” 实际要求为: “张a”、“张c”、“赵a”、“赵b”、“赵e”

TomasWell commented 3 years ago

我是在getFirstLetter方法里面做出的修改,如果有问题还望斧正

    for (NSString* word in wordArr) {
        //如果word是小写 为汉字转的拼音 提取首字符 否则 保留全部
        if (word.length == 0) {

        } else {

            NSInteger c_index = [wordArr indexOfObject:word];
            NSString* c;
            if (c_index == 0) {
                c = word;
            } else {
                if (word.length > 1) {
                    c = [word substringToIndex:0];
                } else {
                    c = @"a";
                }
            }

// char c = [word characterAtIndex:0]; // if ((c>96)&&(c<123)) { // [result appendFormat:@"%c",c]; // }else{ [result appendString:word]; // } } }

TomasWell commented 3 years ago

我是在getFirstLetter方法里面做出的修改,如果有问题还望斧正

    for (NSString* word in wordArr) {
        //如果word是小写 为汉字转的拼音 提取首字符 否则 保留全部
        if (word.length == 0) {

        } else {

            NSInteger c_index = [wordArr indexOfObject:word];
            NSString* c;
            if (c_index == 0) {
                c = word;
            } else {
                if (word.length > 1) {
                    c = [word substringToIndex:0];
                } else {
                    c = @"a";
                }
            }

// char c = [word characterAtIndex:0]; // if ((c>96)&&(c<123)) { // [result appendFormat:@"%c",c]; // }else{ [result appendString:word]; // } } }

Baymax0 commented 3 years ago

我大致了解你的需求了。评论一下。 1、不应该在这个getFirstLetter方法里改,这只是一个单纯返回首字母的方法,改了方法名和实际返回结果不同了。 2、你的写法也没满足你的需求,只能区分拼音不同的,对于“赵”和“招”,你还是会乱 3、如果想区分汉字,应该对汉字做处理,不是对拼音做处理。在排序比较的时候,改进用于比较的key “首字母” 改进为-> “首字母”+“首汉字的unicode” 4、最后在分组和排序的时候做出响应的改进。

Baymax0 commented 3 years ago

这只是我暂时想到的思路。 另外说一下,抱歉这么久才看到,经常不注意noti。 我已经转swift很久了,所以oc版本应该随缘更新了。 下次更新为swift版本更新缓存机时,会一起改进这个需求的。最后感谢你的提议🙏