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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:32:21+00:00 2026-05-13T10:32:21+00:00

I saw this thread but wanted to confirm: How to convert NSNumber objects for

  • 0

I saw this thread but wanted to confirm:

How to convert NSNumber objects for computational purposes?

So basically anytime you want to deal with these objects you have to unpack their ivars, and then pack them back up into new objects, presumably NSNumbers?

That seems hella weak(and a large pain in the backside, no?).

How do you folks work with these?

Do you avoid them? Subclass them? is there mutable versions?

This just seems like a lot of work to deal with them, would love to hear their benefits and ways more experienced programmers have used them, or what tactics they have used to avoid using them.

Thanks,

Nick

  • 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-13T10:32:22+00:00Added an answer on May 13, 2026 at 10:32 am

    So basically anytime you want to deal with these objects you have to unpack their ivars, and then pack them back up into new objects, presumably NSNumbers?

    Yes. (By the way calling doubleValue does not just mean unpack the ivar. There maybe some conversions too.)

    That seems hella weak(and a large pain in the backside, no?).

    This “boxing” is necessary because primitive numbers by themselves to not support Objective-C (Foundation.framework)’s ref-counting scheme. For example, you have to box a number as NSNumber in order to store them in an NSArray.

    Do you avoid them?

    You can’t.

    Subclass them?

    You shouldn’t, but if you have to, follow how it’s suggested:

    • As with any class cluster, if you create a subclass of NSNumber, you have to override the primitive methods of its superclass, NSValue. Furthermore, there is a restricted set of return values that your implementation of the NSValue method objCType can return, in order to take advantage of the abstract implementations of the non-primitive methods. The valid return values are “c”, “C”, “s”, “S”, “i”, “I”, “l”, “L”, “q”, “Q”, “f”, and “d”.

    If all you want is add some convenient methods e.g. -numberByAddingNumber:, use a category:

    @implementation NSNumber (MyExtension)
    -(NSNumber*)numberByAddingNumber:(NSNumber*)another {
       double myVal = [self doubleValue];
       double anotherVal = [another doubleValue];
       return [NSNumber numberWithDouble:myVal + anotherVal];
    }
    @end
    ...
    NSNumber* a, *b;
    ...
    NSNumber* c = [a numberByAddingNumber:b];
    ...
    

    is there mutable versions?

    No.

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

Sidebar

Related Questions

I saw this thread: What are the biggest differences between Scala 2.8 and Scala
I saw this post on SO already but it still begs the question, at
I saw this bit of code in another thread void foo { int *n
I saw that there's many, many thread about this on the web, also in
How can i change system culture that affects all pages(programmatically)? i saw this thread.
I saw this thread on Stack Overflow regarding converting between DBNull and nullable types
I just saw this thread, describing how to add conditional macros: Conditional value for
I saw this in an answer to another question , in reference to shortcomings
I saw this same question for VIM and it has been something that I
I saw this quote on the question: What is a good functional language on

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.