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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:33:15+00:00 2026-05-23T11:33:15+00:00

I saw this post: How to sort an NSMutableArray of objects by a member

  • 0

I saw this post: How to sort an NSMutableArray of objects by a member of its class, that is an int or float

And had something similar, but I wasn’t sure how it all works and was hoping for some guidance. I have an Array of Marker objects that have a Type ivar that takes on values of 0, 1, 2. I want to have a check box that says what to order by, 0, 1, or 2.

I started off by trying to doing something similar in my own method:

- (NSComparisonResult)Type:(id)otherObject {
    if ([self Type] > [otherObject Type]) {
        return NSOrderedAscending;
    }
    else if ([self Type] < [otherObject Type]) {
        return NSOrderedDescending;
    }
    else {
        return NSOrderedSame;
    }
}

In my .h file:

NSInteger _type; 
@property NSInteger Type;

I get the two warnings:
Ordered comparison between pointer and integer (‘id’ and NSInteger’)
Method – Type not found (return type defaults to ‘id’)

I don’t think I understand what is happening when you call the sort method. Thanks.

  • 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-23T11:33:15+00:00Added an answer on May 23, 2026 at 11:33 am

    What happens if you’re explicit about the input type being a YourObjectType * (or whatever your object is called) rather than id? To be completely safe you should check the type of the incoming object anyway (as it may not respond to ‘Type’ at all, or may return something else with the same selector), so you’d end up with:

    - (NSComparisonResult)Type:(YourObjectType *)otherObject {
        if(![otherObject isKindOfClass:[YourObjectType class]]) return NSOrderedSame;
    
        if ([self Type] > [otherObject Type]) {
            return NSOrderedAscending;
        }
        else if ([self Type] < [otherObject Type]) {
            return NSOrderedDescending;
        }
        else {
            return NSOrderedSame;
        }
    }
    

    I’m basically making the same guess as highlycaffeinated, that the compiler is failing to correctly determine the return type of ‘Type’, but my guess is that it’s because of an incorrect compiler prediction about the incoming object.

    To explain the whole process:

    When you ask NSArray to sortUsingSelector, it’ll apply some sorting algorithm that requires it to be able to compare any two objects within it. When it needs to compare two objects, it’ll send the selector you supplied, then use the result you return — so with Ascending/Descending you’re specifying the order that the two objects would appear in if correctly sorted.

    For example, if you had an NSArray filled with objects of type SillyObjectType and you issued a sortUsingSelector:@selector(compare:) then NSArray would apply some unspecified sorting algorithm that involved sending the selector compare: to instances of SillyObjectType. Each SillyObjectType is being asked “should you come before, after, or at an equal place to this other object?”. It replies with NSOrderedAscending, Descending or Same.

    This is one place where ObjC’s dynamic dispatch gives a slightly different way of writing the thing than you’d use in e.g. C++. The selector will be sent to the objects in the array, so you should implement it on those objects. In each case the normal rules apply, so self will be that instance of that class.

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

Sidebar

Related Questions

I saw this same question for VIM and it has been something that I
(this is a re-post of a question that I saw in my RSS, but
I saw an earlier post which is trying to do a similar sort of
I saw this post: Typos… Just use option strict and explicit please.. during one
I saw this post on Sitepoint quoting a statement by Rasmus Lerdorf which goes
I saw this signature on the ListView class: public ListView..::.ListViewItemCollection Items { get; }
So I saw this post here and read it and it seems like bulk
I saw this post but mine is slightly different: Rails ActionMailer with multiple SMTP
I saw this post Ruby on Rails - Awesome nested set plugin but I
I saw this excellent post: http://sqldud.blogspot.com/2009/01/how-to-convert-csv-to-xml-using-c.html I have a csv file with the column

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.