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
Yes. (By the way calling
doubleValuedoes not just mean unpack the ivar. There maybe some conversions too.)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
NSNumberin order to store them in anNSArray.You can’t.
You shouldn’t, but if you have to, follow how it’s suggested:
If all you want is add some convenient methods e.g.
-numberByAddingNumber:, use a category:No.