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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:30:24+00:00 2026-06-11T05:30:24+00:00

I have the following mutable array: NSMutableArray *persons = [[NSMutableArray alloc]initWithObjects:person1, person2, person3, nil];

  • 0

I have the following mutable array:

NSMutableArray *persons = [[NSMutableArray alloc]initWithObjects:person1, person2, person3, nil];

where every person is an object, which contains (NSInteger) personAge and (NSString*) personName properties.
Now I want to sort this array by personAge. So I tried the following:

[persons sortUsingComparator:
     ^NSComparisonResult(id obj1, id obj2)
     {
         Person *p1 = (Person*)obj1;
         Person *p2 = (Person*)obj2;

        return [p1.personAge compare: p2.personAge];

     }];

    NSLog(@"%ld", [persons componentsJoinedByString:@" "]);

But I’m getting a “Bad receiver type ‘NSInteger’ (aka ‘long’)” error message in the return line. Also I have a warning in the NSLog line: “Format specifies type ‘long’ but the argument has type ‘NSString *'”. How do I fix it?

  • 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-11T05:30:26+00:00Added an answer on June 11, 2026 at 5:30 am

    Shouldn’t you use something like this instead?

    [persons sortUsingComparator:
        ^NSComparisonResult(id obj1, id obj2) {
            Person *p1 = (Person*)obj1;
            Person *p2 = (Person*)obj2;
    
            if (p1.personAge > p2.personAge) {
                return (NSComparisonResult)NSOrderedDescending;
            }
    
            if (p1.personAge < p2.personAge) {
                return (NSComparisonResult)NSOrderedAscending;
            }
    
            return (NSComparisonResult)NSOrderedSame;
        }
    ];
    

    The thing is that you have rely on the compare method which doesn’t exist on NSInteger: it is only a typedef of int. So you want to compare integer value instead and returns an NSComparisonResult value to denote the ordering of your object accordingly.

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

Sidebar

Related Questions

I have the following code which has a mutable Person class, String and a
I have a mutable array with the following contents: 2012-05-26 23:38:09.606 [8147:f803] log (
I have following piece of code NSMutableArray *mutArray = [[NSMutableArray alloc] init]; [mutArray addObject:
I have problem with following code. mySpriteArray=[[NSMutableArray alloc] init]; star=[CCSprite spriteWithFile:@22.png]; for(int i=0;i<10; i++)
I am trying a simple application where I have a mutable array of mutable
Help please :) I have set up a mutable array as follows - (void)viewDidLoad
I have a situation which resembles the following: let mutable stopped = false let
I have the following code: class Hello(object): def __init__(self, names): self.names = names def
I have an ivar mutable array which i setup in viewDidLoad as follows: names
I have a view controller I'm storing into a mutable array. - (void)pushViewController:(KAViewController *)viewController

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.