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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:47:42+00:00 2026-05-28T02:47:42+00:00

I use several NSComparators in my iOS app which compare objects by NSString or

  • 0

I use several NSComparators in my iOS app which compare objects by NSString or NSNumber properties. This is fairly easy because NSString has caseInsensitiveCompare: and NSNumber has compare:. How do I compare bools or ints though? For booleans, code could get pretty tangled quite quickly, as my comparision functions take a (bool)ascending parameter. I’ve noticed Objective C often has obscure global functions for this type of thing.

Currently I’m using this code to compare booleans:

NSComparator comp = ^(id id1, id id2) {
    ListItem *comp1 = nil, 
             *comp2 = nil;
    if([id1 isKindOfClass:[ListItem class]]){
        if(ascending){
            comp1 = (ListItem*)id1;
            comp2 = (ListItem*)id2;
        }else{
            comp1 = (ListItem*)id2;
            comp2 = (ListItem*)id1;
        }
    } 
    if(h1!=nil && h2!=nil){
        if((h1.isInBasket && h2.isInBasket) || (!h1.isInBasket && !h2.isInBasket)){
            return 0;
        } else if(h1.isInBasket && !h2.isInBasket) {
            return 1;
        } else {
            return -1;
        }
    } else {
        return 0;
    }

}

  • 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-28T02:47:43+00:00Added an answer on May 28, 2026 at 2:47 am

    Bools (BOOL, Boolean) and integers (int, long, unsigned, etc.) are just plain C integral types and you compare them with the standard C comparison operators <, >, == etc. Same holds for char (also an integral type), float, etc. and the named variants such as NSInteger.

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

Sidebar

Related Questions

I use several forms on my site to send data to MySQL. Which is
In my web app I use several asmx (Web Services) from the same provider,
I'm developing a Mac OS X Cocoa app and want to use several .dylib
Sometimes I need to use several disposable objects within a function. Most common case
In our web-aplication we use several alerts like this: I need to retrieve link
I'm writing a web application in which i use several thirdy party commands calling
I use several jquery plugins on my website, most of which are actually used
If i want to use several icon in my app should i enter all
I have a situation where I want to use several server side controls, which
In my app, I use several tableviews I need to put loading screen when

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.