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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:18:28+00:00 2026-05-16T04:18:28+00:00

Hi I am new to iPhone. What I am doing is sorting the array

  • 0

Hi I am new to iPhone. What I am doing is sorting the array of images; that array consists of 22 elements. I am writing the code for that:

NSMutableArray *images2 = [[NSMutableArray alloc] initWithArray:images]
int n=22;
for (int i=0;i<n;i++){

    for (int j=1;j<n-i;j++){
        if(count[j-1]>count[j]){
            int t = count[j-1]
            count[j-1] = count[j]
            count[j] =t ;

            NSString *tempimage = [images objectAtIndex:j-1];
            [images2 replaceobjectAtIndex:j-1 withobject:[image2 objectAtIndex:j]];
            [images2 replaceobjectAtIndex:j withobject:tempimage];
        }
    }
}
images = [[NSMutableArray alloc] initWithArray:images2];

It sorts finely but at the end it replaces 21st image. What is the wrong in this? If there are any mistakes please post the correct code. What I need is to replace first image to last and second image to first.

  • 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-16T04:18:29+00:00Added an answer on May 16, 2026 at 4:18 am

    Solution to your problem: don’t implement sorting yourself, let the framework do it for you. NSMutableArray has a number of sorting methods that will do all this stuff for you. If you can clarify a few points (see the comments on your question) we can help you construct the proper sorting method call.

    – exchangeObjectAtIndex:withObjectAtIndex:
    – sortUsingDescriptors:
    – sortUsingComparator:
    – sortWithOptions:usingComparator:
    – sortUsingFunction:context:
    – sortUsingSelector:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started doing some reading (new to xcode/iphone development) into web services and
I am really new to iPhone dev. I am evaluating whether to use Monotouch
So new to objective-c and iphone/ipad development. Trying to get my feet wet with
I'm fairly new to core data and iphone programming. Maybe this is an obvious
I have an iPhone project that starts out with a standard UIView based Window...
I am currently using XCode 3.2.3 and iOS4. I'm working on an app that
I am relatively new to Objective-C and now I have a problem in my
So I'm new to programming but I'm managed to create the groundwork for an
I'm programming a new engine for iOS and I'm at a point where I
I'm porting Chicken of VNC Mac application into iphone application I am having source

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.