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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:48:13+00:00 2026-05-20T18:48:13+00:00

I spent some time today chasing down two bugs, and ended up fixing both

  • 0

I spent some time today chasing down two bugs, and ended up fixing both of them using the same solution.

Now that I have the solution, I was hoping to get some clarity behind it.

I’m comparing an attribute from Core Data (Integer 16/NSNumber) with an Integer (ABPropertyID & ABMultiValueIdentifier).

The bug was in this comparison, and oddly enough, only showed itself after I had killed the app (from the background tray), reopened it, and run through the same process that included the comparison. Anyways…

This is what stopped working after a restart:

if (myNumber.aProperty == [NSNUmber numberWithInt:anInteger]) { /* do stuff here */ }

And these are the two solutions, which so far, are working perfectly:

if ([myNumber.aProperty integerValue] == anInteger) {/* do stuff here */ }

if ([myNumber.aProperty isEqualToNumber:[NSNumber numberWithInt:anInteger]]) { /* do stuff here */ }

To me, they all look identical. I’m always either converting the NSNumber to an integerValue, or converting the integer to an NSNumber.

Any ideas?

  • 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-20T18:48:14+00:00Added an answer on May 20, 2026 at 6:48 pm

    Do not use == to compare NSNumbers. Most of the time you’ll be comparing two distinct objects, so the comparison won’t evaluate to true. If you look at your if condition, notice that you’re particularly comparing your property to a brand new NSNumber object.

    Since NSInteger is a Cocoa wrapper for certain value types, comparing NSIntegers with == works fine.

    The implementation of isEqualToNumber: probably takes the wrapped value types and compares them too.

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

Sidebar

Related Questions

I've spent some time today playing with getting the source for python 3.1.1 to
I've spent some time today looking for a pure ruby library that will parse
I've spent some time trying to find a way CodeRush could add using when
I recently spent some time chasing an annoying little bug and I'm looking for
Just had my mind going today. I spent some time in IE debug mode,
So Ive spent quite some time today with sql lite and saw the .net4
I spent some time checking out JBoss AS7 today. I am impressed with what
Having spent some time working on data warehousing, I have created both ETL (extract
I spent some time trying to remove layout (defined in _ViewStart) using: @Layout =
I just spent some time debugging a problem that boiled down to forgetting to

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.