OC数组中文排序

 

 

-(void)sortStudentInfo

{

    if(studentInfoArray && studentInfoArray.count > 0)

    {

        for(TWDetaiAnswerResultStudentInfoVO *studentInfo in studentInfoArray)

        {

            studentInfo.sortName = [NSMutableString stringWithString:studentInfo.studentName];

            CFStringTransform((CFMutableStringRef)studentInfo.sortName, NULL, kCFStringTransformToLatin, false);

        }

        

        NSMutableArray *array = [NSMutableArray arrayWithArray:studentInfoArray];

        

        array = [array sortedArrayUsingComparator:^NSComparisonResult(TWDetaiAnswerResultStudentInfoVO *studentInfo1, TWDetaiAnswerResultStudentInfoVO *studentInfo2)

                            {

                                NSComparisonResult result = [studentInfo1.sortName compare:studentInfo2.sortName];

                                return result;

                            }];

        

        [studentInfoArray removeAllObjects];

        [studentInfoArray addObjectsFromArray:array];

    }

}

原文地址:https://www.cnblogs.com/xiangjune/p/5189170.html