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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:55:59+00:00 2026-06-07T10:55:59+00:00

Here is my NSArray myArray = [NSArray arrayWithObjects: @a, @b, @c, @d, @e, nil];

  • 0

Here is my NSArray

myArray = [NSArray arrayWithObjects: @"a", @"b", @"c", @"d", @"e", nil];

Now I’m looping through the array like this:

int size = [myArray count];
NSLog(@"there are %d objects in the myArray", size);

for(int i = 1; i <= size; i++) {
    NSString * buttonTitle = [myArray objectAtIndex:i]; 
    // This gives me the order a, b, c, d, e 
    // but I'm looking to sort the array to get this order
    // e,d,c,b,a

    // Other operation use the i int value so i-- doesn't fit my needs
}

In the for loop this gives me the order:

a, b, c, d, e 

but I’m looking to sort the array to get this order:

e, d, c, b, a

Any thoughts?

I need to keep the array in the original sort order as well.

  • 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-07T10:56:00+00:00Added an answer on June 7, 2026 at 10:56 am

    Try calling reverseObjectEnumerator on the array and using a for-in loop to cycle through the objects:

    NSArray *myArray = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
    
    // Interate through array backwards:
    for (NSString *buttonTitle in [myArray reverseObjectEnumerator]) {
        NSLog(@"%@", buttonTitle);
    }
    

    This will output:

    c
    b
    a
    

    Alternatively, you can reverse the array in place if you’d like to iterate through the array by index or do something else with it:

    NSArray *reversedArray = [[myArray reverseObjectEnumerator] allObjects];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

why is error:&error used here (objective-c) NSError *error = nil; NSArray *array = [moc
Here is my piece of code that creates buttons programmatically: NSArray *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@Cover_0.png],
Here's my code: -(void)randommoves { NSArray *possiblemoves =[NSArray arrayWithObjects:@R ,@R' ,@L ,@L' ,@B ,@B'
How do I fix the leak here? -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { if(searching){ return nil;
Here is the code that I have for my cell of my UITableView: forKeys:[NSArray
Here is the code in a function I'm trying to revise. This example works
I'm trying to load the following plist into an NSArray: Here is the code
I declare an NSArray in my code then building the array from another array.
I know this is a stupid question, but I've looked for 45 mins now
I have an nsarray that when I NSLog it from one of my methods

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.