Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:03:50+00:00 2026-06-04T17:03:50+00:00

I have an app that uses address book. I am trying to display sorted

  • 0

I have an app that uses address book. I am trying to display sorted list of names from address book using

sortedArray = [arr_contactList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

and then when user selects one of the contacts, its phone number is displayed.

I am able to sort iPhone address book phone numbers.

I use following to sort phone numbers:

ABRecordRef source = ABAddressBookCopyDefaultSource(ab);
NSArray *thePeople = (NSArray*)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(ab, source, kABPersonSortByFirstName);

NSString *name;
for (id person in thePeople)
{
    name = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

    ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);

    for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
    {  
        NSString* num = (NSString*)ABMultiValueCopyValueAtIndex(phones, j);

        CFStringRef locLabel1 = ABMultiValueCopyLabelAtIndex(phones, j);

        NSString *phoneLabel1 =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel1);

        [tempPhoneArray addObject:num];        
    }       
}

But my actual problem is, my names array has contacts that begin with special characters on top of the list, and when I select phone nos, the contact list sorted starts with alphabet A. So I am getting wrong phone numbers.

How do I match both the sorts – the name sort and numbers sort?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:03:51+00:00Added an answer on June 4, 2026 at 5:03 pm

    In this example, you would be making 27 arrays, 1 for each letter, but the concept can be applied to any checking of special characters vs upper/lowercase. Hope this helps.

    const int capacity = 27;    
    NSMutableArray *subArrays = [NSMutableArray array];
    
    //Prepopulate the subArray with 26 empty arrays
    for(int i = 0; i < capacity; i++)
        [subArrays addObject:[NSMutableArray array]];
    char currFirstLetter = 'a';
    
    for(int i = 0; i < sortedArray.count; i++)
    {
        NSString *currString = [[sortedArray objectAtIndex:i] lowercaseString];
    
        NSLog(@"%@", currString);
        NSLog(@"%c", [currString characterAtIndex:0]);
        NSLog(@"%c", currFirstLetter);
    
        if([currString characterAtIndex:0] == currFirstLetter)
        {
            //65 is the position of 'a' in the ascii table, so when we subtract 97, it correlates to 0 in our array.
            [[subArrays objectAtIndex:currFirstLetter-97] addObject:[sortedArray objectAtIndex:i]];
        }
        else if([currString characterAtIndex:0] < 65 || ([currString characterAtIndex:0] > 90 && [currString characterAtIndex:0] < 97) || [currString characterAtIndex:0] > 122)
        {
            //If it's a symbol (65-90 are uppercase, 97-122 are lowercase)
            [[subArrays objectAtIndex:26] addObject:[sortedArray objectAtIndex:i]];
            //Increment the letter we're looking for, but decrement the count to try it again with the next letter
        }
        else
        {
            currFirstLetter++;
            i--;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that uses a transition file to flip from page to
I have a Flash app that uses an implementation of SWF Address for deep
I have an App that does forward geocoding (get coordinates given address) to display
I have a GWT app that uses Google Maps and Im trying to create
I have an app that uses the ActionBar with tabs in combination with Fragments.
I have an app that uses webView. In the home screen of a website
I have an app that uses the built-in flip animation to switch between the
I have an app that uses EF. To test my stuff I generally wrap
I have an app that uses the python/c api and I was wondering what
I have an app that uses a tableview, along with a UIButton that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.