在iPhone上按字母顺序排列ABRecords

我正在使用以下代码检索联系人姓名:
for( int i = 0 ; i < n ; i++ )
{
    Contact *c = [[Contact alloc] init];

    ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
    NSString *firstName = (NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    NSString *lastName = (NSString *)ABRecordCopyValue(ref, kABPersonLastNameProperty);
    c.firstName = firstName; //[NSString stringWithFormat:@"%@ %@", firstName, lastName];
    c.lastName = lastName;

    [contacts addObject:c];

    [c release];
}
有没有人知道按字母顺序排序这个列表的方法?我读过
sortedArrayUsingSelector:@selector(compare:)
但我不知道这应该是怎么回事。     
已邀请:
NSSortDescriptor *mySorter = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
[contacts sortUsingDescriptors:[NSArray arrayWithObject:mySorter]];
[mySorter release];
    
此方法将允许您尊重用户的首选或姓氏排序首选项。
contacts = (bridgedPeople as [ABRecord]).sort {
    (person1, person2) -> Bool in
    return .CompareLessThan == ABPersonComparePeopleByName(person1, person2, ABPersonGetSortOrdering())
}
专业提示:粗体显示您正在排序的名称部分;当你混合有[没有名字,没有姓氏,名字和姓氏]的联系人时,它会变得混乱     

要回复问题请先登录注册