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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:02:31+00:00 2026-06-03T03:02:31+00:00

I have a project which does several network operations. For easy control I have

  • 0

I have a project which does several network operations. For easy control I have given each operation a unique Id, defined as a NSNumber because i have to perform operations with objects and Array and is easier this way:

#define LOGIN_OPERATION                     [NSNumber numberWithInt:0]
#define REGISTER_USER_OPERATION             [NSNumber numberWithInt:1]
#define VERIFY_USER_OPERATION               [NSNumber numberWithInt:2]
#define REGISTER_USER_DATA_OPERATION        [NSNumber numberWithInt:3]
#define FORGOT_PASSWORD_OPERATION           [NSNumber numberWithInt:4]
#define PASSTIME_REGISTER_OPERATION         [NSNumber numberWithInt:5]
#define PASSTIME_VERIFY_TOKEN_OPERATION     [NSNumber numberWithInt:6]
#define PASSTIME_OPERATION                  [NSNumber numberWithInt:7]
#define SERVICES_OPERATION                  [NSNumber numberWithInt:8]
#define MAIL_SUPPORT_OPERATION              [NSNumber numberWithInt:9]
#define UPDATE_USER_INFO_OPERATION          [NSNumber numberWithInt:10]
#define OBTAIN_CACS_OPERATION               [NSNumber numberWithInt:11]
#define GET_PREPAID_BALANCE_OPERATION       [NSNumber numberWithInt:12]
#define UPDATE_SERVICES_OPERATION           [NSNumber numberWithInt:13]

then I simply used among my project instructions as the following, which has worked pretty well during the last year.

- (void) processNetworkResponseForOperation: (NSNumber*) opId {

    if (opId == SERVICES_OPERATION) {
        //do something
    } else if (opId == UPDATE_SERVICES_OPERATION) {
        //do something
    }

}

However today i added the last operation (number 13) and all the == operations result false, just with that number!, i have used the debugger to assure that the value is ok, but i can only get the condition to true if I use: [opId isEqualToNumber: UPDATE_SERVICES_OPERATION] which is pretty long.

I understand that NSNumber is an object and thus == may not be the best choise, but why does it works with all other operations among the project but with #13 wont work?

Any help will be appreciated.

Edit
Well i tried with bigger numbers and i have the same problem, but for example if I switch theUPDATE_SERVICES_OPERATION number with another op number, it now does the UPDATE_SERVICES_OPERATION but it wont do the operation which i switched the number. So why doesn’t it work with newer numbers :S, or is it just a build problem on xcode? (i will restart and update)

  • 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-03T03:02:34+00:00Added an answer on June 3, 2026 at 3:02 am

    You should never compare an NSNumber directly like you are doing here because it is an object and not a simple type. Your current code is depending on the equality of the objects memory addresses not their value. Read here for more information Comparing objects in Obj-C.

    You should never use == to compare for object equality but instead the isEqual: function on NSObject and usually only if you want to be sure the objects you are comparing are the same instance. The code below should fix your problem.

    
    - (void) processNetworkResponseForOperation: (NSNumber*) opId {
    
        if ([opId intValue] == [SERVICES_OPERATION intValue]) {
            //do something
        } else if ([opId intValue] == [UPDATE_SERVICES_OPERATION intValue]) {
            //do something
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: My (C++-)project consists of several subprojects. In each, I
I have a GitHub project which does the same thing (a simple RogueLike game
I have several classes in a project which need to only be in certain
I have been working on a project which had been split over several servers
I have a project which it's domain contain following classes: Courier Customer Food Order
I have a project which exposes object model to use by different types of
I have a project which builds correctly from the command line. On one of
I have a project which has a set of binary dependencies (assembly dlls for
We have a project which had to be radically descoped in order to ship
I have a project which as part of the build process creates an XMLBeans

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.