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 968281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:27:15+00:00 2026-05-16T02:27:15+00:00

In my project I roll through a bunch of sql records and populate a

  • 0

In my project I roll through a bunch of sql records and populate a NSMutableDictionary with a string for each key. The keys are important because I use them as section titles in my TableView.

The problem I have is that I would like the sections in a certain order. When I call allKeys the order of the keys isn’t the same as the order they went into the NSMutableDictionary. I more or less understand why. My question is how I can make certain values (non alphabetically) appear first before the rest of the values.

Example strings: ‘Blue’, ‘Brown’, ‘Green’, ‘Orange’, ‘Purple’, ‘Red’, ‘Violet’, ‘Yellow’…

I would like to see them ordered like this: ‘Red’, ‘Green’, ‘Blue’, ‘Brown’, ‘Orange’, ‘Purple’, ‘Red’, ‘Violet’

The important part is the “‘Red’, ‘Green’, ‘Blue'”, all other values can be in alphabetical order behind those 3 values.

The only thing I can think of is to order them alphabetically by saying ‘sortedArrayUsingSelector:@selector(compare:)’ and then just trying to remove the strings I am looking for and placing them back in at a smaller index value if they exist. Any better ideas? I am not sure how efficient that is.

  • 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-16T02:27:15+00:00Added an answer on May 16, 2026 at 2:27 am

    Here is the method I came up with. Again, I am not sure how efficient it is, but it works for my purposes.

    -(NSArray *)rearrangeSections:(NSArray *)s {
        NSArray *topSections = [NSArray arrayWithObjects:@"Red", @"Green", @"Blue", nil];
    
        NSArray *reversedTopSections = [[topSections reverseObjectEnumerator] allObjects];
        NSArray *alphabetizedArray = [s sortedArrayUsingSelector:@selector(compare:)];
        NSMutableArray *sections = [NSMutableArray arrayWithArray:alphabetizedArray];
    
        //Loop through our list of sections and place them at the top of the list.
        for (NSString *sectionTitle in reversedTopSections) {
            if ([sections containsObject:sectionTitle]) {
                [sections removeObject:sectionTitle];
                [sections insertObject:sectionTitle atIndex:0];
            }
            //NSLog(@"%@", sections);
        }
    
        NSArray *sortedSections = [NSArray arrayWithArray:sections];
        return sortedSections;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been doing some work lately on a project that makes extensive use of
I need to roll back to a previous version of my project, but I
What is the best practice for updating a project when you want to roll
We are about to roll out a project management system and we came across
Greets. I'm working on a project and thought I would roll up a composite
I'm looking for some information about the roll-out of a python project that uses
I want to use FlashBuilder 4.5.1 to build a flex mobile project that lets
Project: http://design.vitalbmx.com/fave/news.html When I click Add to favorites button (under main pic), in Chrome
Project layout: /project_a /shared /project_b /shared /shared project_a and project_b both need to contain
My project in some part need GPU acceleration to make a fast translation, but

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.