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

  • Home
  • SEARCH
  • 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 3226196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:25:39+00:00 2026-05-17T16:25:39+00:00

hi i have an array of objects which need to be sorted (alphabet on

  • 0

hi i have an array of objects which need to be sorted (alphabet on name)

ArtistVO *artist1 = [ArtistVO alloc];
artist1.name = @"Trentemoeller";
artist1.imgPath = @"imgPath";

ArtistVO *artist2 = [ArtistVO alloc];
artist2.name = @"ATrentemoeller";
artist2.imgPath = @"imgPath2";


ArtistVO *artist3 = [ArtistVO alloc];
artist3.name = @"APhextwin";
artist3.imgPath = @"imgPath2";    

//NSLog(@"%@", artist1.name);
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:artist1];
[arr addObject:artist2];
[arr addObject:artist3];


NSSortDescriptor *lastDescriptor =
[[[NSSortDescriptor alloc]
  initWithKey:@"name"
  ascending:YES
  selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];    

NSArray * descriptors =
[NSArray arrayWithObjects:lastDescriptor, nil];
NSArray * sortedArray =
[arr sortedArrayUsingDescriptors:descriptors];    

NSLog(@"\nSorted ...");
NSEnumerator *enumerator;
enumerator = [sortedArray objectEnumerator];

ArtistVO *tmpARt;
while ((tmpARt = [enumerator nextObject])) NSLog(@"%@", tmpARt.name);    

works fine. but now i need to split this awway up for usage in a grouped uitableview

    self.sortedKeys =[[NSArray alloc]
                  initWithObjects:@"{search}",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",nil];


NSMutableArray *arrTemp0 = [[NSMutableArray alloc]
                     initWithObjects:@"000",nil];    
NSMutableArray *arrTemp1 = [[NSMutableArray alloc]
                     initWithObjects:@"Andrew",@"Aubrey",@"Aalice", @"Andrew",@"Aubrey",@"Alice",@"Andrew",@"Aubrey",@"Alice",nil];
NSMutableArray *arrTemp2 = [[NSMutableArray alloc]
                     initWithObjects:@"Bob",@"Bill",@"Bianca",@"Bob",@"Bill",@"Bianca",nil];
NSMutableArray *arrTemp3 = [[NSMutableArray alloc]
                     initWithObjects:@"Candice",@"Clint",@"Chris",@"Candice",@"Clint",@"Chris",nil];
NSMutableArray *arrTemp4 = [[NSMutableArray alloc]
                     initWithObjects:@"Dandice",@"Dlint",@"Dhris",nil];
NSDictionary *temp =[[NSDictionary alloc]
                     initWithObjectsAndKeys:arrTemp0, @"{search}", arrTemp1,@"A",arrTemp2,
                     @"B",arrTemp3,@"C",arrTemp4,@"D",nil];


self.tableContents =temp;

so all Artist with first letter “a” come in one array … with “b” in one array and so on.

do i need to do some string comparism or is there a better approach?

  • 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-05-17T16:25:40+00:00Added an answer on May 17, 2026 at 4:25 pm

    How about:

    Create an empty NSMutableDictionary.

    Loop through all your strings. For each string:

    • If string is empty, ignore this string.
    • Get a NSString containing first character of the string converted to uppercase. This will be your dictionary key.
    • Look in the dictionary to see if it already contains this key.
    • If not, create a new NSMutableArray containing just your string and add it as the value to this new key.
    • If so, add this string to the end of the existing array.

    End of loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.