OC数组中文排序

时间:2024-06-18 13:03:26

-(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];

}

}