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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:46:13+00:00 2026-06-09T17:46:13+00:00

I am trying to sort an array of NSObjects (a object is of a

  • 0

I am trying to sort an array of NSObjects (a object is of a class). The object class has several variables which I am wanting to use to sort the objects in the array, the variables I am using to sort are of type NSString or NSInteger, I am confident I am sorting NSStrings but for this question I am hoping to get help for sorting a NSInteger.

This is the method I am using to sort the array of objects, It receives an NSMutableArray of objects

- (NSMutableArray *)startSortingTheArray:(NSMutableArray *)unsortedArray
{
    [unsortedArray sortUsingComparator:^ NSComparisonResult(SearchResultItem *d1, SearchResultItem *d2) {
        NSInteger DoorID1 = d1.doorID;
        NSInteger DoorID2 = d2.doorID;
        NSComparisonResult result = [DoorID1 localizedCompare:DoorID2]; // Not sure how to sort these two integers
        if (result == NSOrderedSame) {
            NSString *handel1 = d1.handel;
            NSString *handel2 = d2.handel;
            result = [handel1 localizedCompare:handel2];
         }

I am not sure how to compare the NSInteger, I have read that I could minus each number from itself.. if the number is 0 then they are equal or +1 / -1 etc they are not.. but not sure if thats the best way to approach this.

any help would be appreciated.

  • 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-09T17:46:14+00:00Added an answer on June 9, 2026 at 5:46 pm
    [unsortedArray sortUsingComparator:^ NSComparisonResult(SearchResultItem *d1, SearchResultItem *d2) {
        NSInteger doorID1 = d1.doorID;
        NSInteger doorID2 = d2.doorID;
        if (doorID1 < doorID2)
            return NSOrderedAscending;
        if (doorID1 > doorID2)
            return NSOrderedDescending;
        return [d1.handel localizedCompare: d2.handel];
    }];
    

    as [aString localizedCompare:anotherString] will return NSOrdered(Ascending|Descending|same), you can just return its result for the string case.

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

Sidebar

Related Questions

I'm trying to sort an array, filled with objects from a class i wrote.
I'm trying to sort an array of people objects. The class looks like this.
I'm trying to sort an array of objects by their date property using Async.sortBy,
Trying to sort this array of objects according to (1) depth and (2) weight,
I am trying to sort an array in PHP by date and time which
I'm trying to sort the employees object array by age and i'm getting the
I'm trying to sort an array in descending order in Java using this code:
I'm trying to sort an array of objects with ActionScript 3 . The array
I'm trying to sort a simple array which only contains a few decimal numbers.
Possible Duplicate: Sort array of objects sort an object array in php EDIT: This

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.