- (void)viewDidLoad { [super viewDidLoad]; NSArray* array = @[ @"北京", @"广州", @"上海", @"西安", @"安徽" ]; NSArray* sortArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSString* obj1, NSString* obj2) { CFMutableStringRef string1 = CFStringCreateMutableCopy(NULL, 0, (__bridge CFStringRef)obj1); CFStringTransform(string1, NULL, kCFStringTransformMandarinLatin, NO); CFStringTransform(string1, NULL, kCFStringTransformStripDiacritics, NO); CFMutableStringRef string2 = CFStringCreateMutableCopy(NULL, 0, (__bridge CFStringRef)obj2); CFStringTransform(string2, NULL, kCFStringTransformMandarinLatin, NO); CFStringTransform(string2, NULL, kCFStringTransformStripDiacritics, NO); NSString *str1 = (__bridge NSString *)string1; NSString *str2 = (__bridge NSString *)string2; NSComparisonResult result = [str1 compare:str2 ]; CFRelease(string1); CFRelease(string2); return result; }]; NSLog(@"%@",sortArray); }
时间: 2024-10-19 21:25:01