nsnumber

Cocoa Touch. Why does NSNumber return a difference value for intValue and floatValue?

Ok, this makes absolutely no sense: I creat an NSNumber: NSNumber *n = [NSNumber numberWithInt:37669178]; I then echo the value as an integer and a float: int i = [n intValue]; float f = [n floatValue]; Here are their values: int: 37669178 float: 37669176.000000 Huh!?!?! Could someone please explain to me why this is happening and...

Can I use an NSDecimalNumber anywhere that an NSNumber is expected?

NSDecimalNumber is a subclass of NSNumber, and from what I can tell, it implements all of the NSNumber methods as expected for an NSNumber instance. Given that, is it ok to give NSDecimalNumbers to any code that is expecting an NSNumber? The only possible issue might be code that checks that an argument is an instance of NSNumber, but ...

How do I set an Integer in a UITextfield using Core Data?

I can set text in my managed object like this... [editedObject setValue:textField.text forKey:editedFieldKey]; but I can't set this... [editedObject setValue:numberField.text forKey:editedFieldKey]; In the XCode Template I can set this straight into the Managed Object but like this... setValue:[NSNumber numberWithInt:200] forKey:@...

Why does my program crash when given negative values?

Alright, I am very confused, so I hope you friends can help me out. I'm working on a project using Cocos2D, the most recent version (.99 RC 1). I make some player objects and some buttons to change the object's life. But the weird thing is, the code crashes when I try to change their life by -5. Or any negative value for that matter,...

Can not read and save a number from/into an .plist

Hello, I created a property list with the name propertys.plist. Then I wrote this: NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathComponent:@"speicherung.plist"]; NSMutableArray *plistData = [[NSMutableArray arrayWithContentsOfFile:finalPath] retain]; int a = [[plistData objectAtInd...

Change NSNumber value by allocating new NSNumber?

I understand that NSNumber is immutable, but I still have the need to change it in my app. I use it because it's an object, and therefore usable with @property (if I could, I would use float or CGFloat in a heartbeat, but sadly, I can't). Is there any way to just overwrite the old NSNumber instance? I'm trying this: NSNumber *zero = [[...

get type of NSNumber

I want to get the type of NSNumber instance. I found out on http://www.cocoadev.com/index.pl?NSNumber this: NSNumber *myNum = [[NSNumber alloc] initWithBool:TRUE]; if ([[myNum className] isEqualToString:@"NSCFNumber"]) { // process NSNumber as integer } else if ([[myNum className] isEqualToString:@"NSCFBoolean"]) { // process...

NSNumber >= 13 won't retain. Everything else will.

The code I'm currently working on requires adding an NSNumber object to an array. All of the NSNumbers with value 0-12 are added fine, but 13 onward causes a EXC_BAD_ACCESS. I turned on NSZombieEnabled and am now getting *** -[CFNumber retain]: message sent to deallocated instance 0x3c78420. Here's the call stack: #0 0x01eac3a7 in ___fo...

How to add numbers in a mutable array in iphone?

I am new to iphone development.I want a Nsmutable array to hold numbers from 1 to 100.How i can do it.how can i implement in a for loop.Is there any other way to hold numbers in array in iphone.Please help me out.Thanks. ...

SOAP app variables - NSNumber or NSString for integer?

In a SOAP app, all communication with the server is as text, when the server needs an integer it is the text value that gets sent and returned integers are sent back as text. To have the app working with integers one has to convert the returned strings into numbers e.g. NSInteger but then to, for example, save them to an array they must...

containsObject - why doesen't this work?

Hi. I have an array that I am trying to check wether or not an indexPath(.row) exists in. I use this code: if ([array containsObject:[NSNumber numberWithInt:indexPath.row]]){ NSLog(@"Yep, it exists in there."); } the array consist of the numbers 3, 8 and 2. The index path loads numbers fromm 0 to 8 in a loop. Can anybody see wh...

NSNumber floatValue not equal to NSNumber value

Hi Everyone, First post here. Having a problem with NSNumber's floatValue method -- somehow, it returns an imprecise number. Here's the problem: I store a bunch of NSNumbers in an array, like this: NSArray *a = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.04f], [NSNumber numberWithFloat:0.028f], [NSNumber numbe...

Correctly assigning value to a Core Data attribute with an integer data-type

I'm missing something here, and feeling like an idiot about it. I'm using a UIPickerView in my app, and I need to assign the row number to a 32-bit integer attribute for a Core Data object. To do this, I am using this method: -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { ...

NSTimer calculate hours

I am using an NSTimer which I have working to show minutes and seconds. But I am confused about the math needed to calculate hours. I am using: - (void)updateCounter:(NSTimer *)theTimer { static int count = 0; count += 1; int seconds = count % 60; int minutes = (count - seconds) / 60; // Not sure how to calculate h...

NSNumbers in archived array dissappear.

Okay I've made an array of NSNumber objects that I've stored into an NSMutableArray. When the game loads it's unarchived and retained but all the NSNumber objects are gone. Here's my code: times = [[NSMutableArray alloc] initWithObjects:[[NSNumber alloc] initWithFloat:time],nil]; [NSKeyedArchiver archiveRootObject:times toFile:@"times"]...

NSNumbers in stored array disappear.

So I stored an NSMutableArray of NSNumber objects into the file "times.plist" then I load it and retain it on launch and the NSLog shows the correct value, but later the [times count] equals 0. Why are the NSNumbers disappearing? times = [[NSMutableArray alloc] initWithObjects:[[NSNumber alloc] initWithFloat:time],nil]; ... [times writ...

Problem with NSNumber and plotting a graph with Core-Plot

I try to plot a Bar Chart with Core-Plot with an Array (content are NSIntegers) given one view before. After transfering the Array in an NSInteger, i must convert it into a NSDecimalNumber, and in this process, my NSInteger (for example 45) becomes "60900224"... Here's the code extract: -(NSNumber *)numberForPlot:(CPPlot *)plot field:...

Help with a method that returns a value by running another object's method

I have a Class that runs the following method (a getter): // the interface @interface MyClass : NSObject{ NSNumber *myFloatValue; } - (double)myFloatValue; - (void)setMyFloatValue:(float)floatInput; @end // the implementation @implementation - (MyClass *)init{ if (self = [super init]){ myFloatValue = [[NSNumber alloc]...

Problem when converting NSString to NSNumber in iPhone

Hey I am having problem when converting string (YaxisData) to NSNumber. I have to return a NSNumber for Core-plot to get the graph done but its not working. Here's the sample code -(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{ NSNumber *num = [NSNumber numberWithDouble:[[YaxisData...

Unable to set class properties

Now Im sure Im doing something extremely schoolboy here, but Im seriously hitting my head against a wall, for some reason Im getting EXEC_BAD_ACCESS when trying to set an NSNumber property on a custom class. Think Im having one of those days! Here my test h and m files: // Test.h #import <Foundation/Foundation.h> @interface Test : ...