nsnumber

How to add two NSNumber objects?

Now this must be easy, but how can sum two NSNumber? Is like: [one floatValue] + [two floatValue] or exist a better way? ...

NSMutableArray add Object as pointer only?

Hello I have this little code NSMutableArray *myArray = [[NSMutableArray alloc] init]; NSNumber *myNumber = [NSNumber numberWithDouble:752.65]; [myArray addObject:myNumber]; With this code I store Objects inside an array. But now I have two objects independent from each other. If I change myNumber after it's been added to the a...

Determine if NSNumber is NaN

How can I determine if a Cocoa NSNumber represents NaN (not a number)? This emerges, for example, when I parse a string that has an invalid (non-numeric) contents. ...

Xcode debugging: View value of NSNumber ??

Is it possible to see the numeric value of an NSNumber in the debugger datatip on in the variable watch window? I store an Integer value in NSNumber and want to see this value during debugging. I tried some of the data formatters in the debugger already, but it wasn't much help. ...

NSNumber out of scope?

I've written an Objective-C class and I'm using a shared instance of it across several of the views in my iPhone project. Its member variables include bools, ints, NSStrings and one NSNumber. The shared instance seems to work just fine across the scope of my application, except for the NSNumber which the debugger tells me is "out of scop...

Is NSNumber overkill for an instance-level counter?

I'm new to Objective-C and Cocoa. I've read that NSInteger and NSNumber are preferred when working with simple integers because they're the "platform-safe" versions of the primitive numeric types (and in NSNumber's case, wrapped in an object). So, I need a counter in my class that gets incremented when an NSTimer fires. On an Apple fo...

Using MPMediaPlaylistPropertyPlaylistAttributes and bitwise operators on NSInteger- Objective C (iPhone)

Hello, and thanks in advance for you time. I am trying to filter out certain types of playlists for an iphone app (genius and On-the-go, specifically). the documentation says that the property attribute MPMediaPlaylistPropertyPlaylistAttributes will return the attributes associated with a playlist in the form of an NSNumber containing a...

using NSNumberFormatter with NSDecimalNumberHandler in the iphone sdk

as a quick test of formatting very large, precise numbers i'm doing: (number is a synthesized NSDecimalNumber...) number = [[NSDecimalNumber alloc] initWithDecimal:[[NSDecimalNumber numberWithDouble:420000008698643507200000.0F] decimalValue]]; DLog(@"unformatted: %@", [number stringValue]); which gives me: "unformatted: 4200000086986...

Does NSNumber add any extra bytes to the number it holds?

I'm working with Objective-C and I need to add int's from a NSArray to a NSMutableData (I'm preparing a to send the data over a connection). If I wrap the int's with NSNumber and then add them to NSMutableData, how would I find out how many bytes are in the NSNumber int? Would it be possible to use sizeof() since according to the apple d...

How do you get the int and modulo (mod) of division with an NSDecimalNumber

I am confused by NSDecimalNumber and its "behaviors". I have an NSDecimalNumber that represents a dollar value, say $37.50. I'd like to find out how many times say 5.0 goes into that number and then know what's left over. I can get the straight division and get 7.50 but I want 7 mod 2.50. I could convert to an integer but need to save th...

Trouble with NSDecimalNumber's decimalNumberByDividingBy:withBehavior:

I always seem to run into trouble with NSDecimalNumber! Today, I get this error: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFNumber decimalNumberByDividingBy:withBehavior:]: unrecognized selector sent to instance 0xd1fb10'" Here is the source of the error: - (void)setUpInstance { ...

Storing and retrieving unsigned long long value to/from NSString

Hi I have an unsigned long long value which I want to store into an NSString and retrieve from the string. Initially I have the value in an NSNumber and I am using this to get the string NSString *numStr = [NSString stringWithFormat:@"%llu", [myNum unsignedLongLongValue]]; where myNum is an NSNumber. To get back the NSNumber from t...

Storing optional NSNumber in Core Data

In my core data model, I have an entity with an optional NSNumber attribute. How do I test to see if the value in that attribute is valid or not? When I test for nil... doesn't work. [self numberAttribute] == nil // always returns NO When I test for a zero value int, that doesn't work. [[self numberAttribute] intValue] == 0 /...

Convert NSNumber (double) value into time

Hey all, i try to convert a value like "898.171813964844" into 00:17:02 (hh:mm:ss). How can this be done in objective c? Thanks for help! ...

Formatted absolute value of an NSNumber

Well, it's actually the sum of an array of NSDecimalNumbers I'd like to get the absolute value of... I constantly feel like I'm fighting the framework with all the conversions & typecasting that are required...from double to NSNumber to NSDecimalNumber and back and...all while trying to maintain the precision that NSDecimalNumber affords...

Objective C - NSNumber, NSInteger, ...

What's the difference between NSNumber and NSInteger? Are there more primitives like these that I should know about/use? Is there one for floats? ...

Can someone post a full example usage of NSNumber?

I'm not even sure, for example, if I can use it like a normal variable. There doesn't appear to be a mutable version. And does mutable mean it's value can be changed? ...

Converting NSNumbers saved in a plist to integers

Saving data: - (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:kFilename]; } - (void)applicationWillTerminate:(NSNotification *)notification { NSMu...

intValue is missing decimals

I have a price that I need to convert based on the selected currency. NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathComponent:@"currency.plist"]; NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain]; int price = [price intValue]; int curre...

How to convert an NSString into an NSNumber

Hello, How can I convert an NSString containing a number of any primitive data type (e.g. int, float, char, unsigned int, etc.)? The problem is, I don't know which number type the string will contains at runtime. I have an idea how to do it, but I'm not sure if this works with any type, also unsigned and floating point values: long lo...