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? ...
Now this must be easy, but how can sum two NSNumber? Is like: [one floatValue] + [two floatValue] or exist a better way? ...
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...
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. ...
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. ...
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...
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...
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...
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...
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...
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...
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 { ...
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...
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 /...
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! ...
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...
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? ...
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? ...
Saving data: - (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:kFilename]; } - (void)applicationWillTerminate:(NSNotification *)notification { NSMu...
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...
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...