nsnumber

How do you sort NSNumber with NSSortDescriptor?

I'm having trouble sorting an NSNumber using NSSortDescriptor. For whatever reason it won't sort into the correct order. What am I doing wrong? - (NSNumber *)sortNumber { NSNumber *sum = [NSNumber numberWithFloat:([self.capacity floatValue] / [self.availability floatValue])]; return sum; } It is defined as an Int32 in the xcdataMode...

XCode warning : Initialization makes pointer from integer without a cast (while trying to assign a value to a NSNumber)

Hi all, I'm stuck with a warning in Xcode while trying to develop a small iPhone App. I've got this piece of code in Xcode : NSNumber *randomNumber = arc4random() % [array count]; If I NSLog randomNumber, everything seems to work but Xcode keeps warning me, saying : Initialization makes pointer from integer without a cast There must...

NSNumber of seconds to Hours, minutes, seconds

I am having a terrible time trying to do something that should be easy. I have a NSNumber value of 32025.89 seconds. I need to represent that in Hours, Minutes, Seconds. Is there a method that spits that out? I can't seem to find a proper formatter. ...

NSNumber, Setting and Retrieving

Hey, I'm messing around with NSNumber for an iPhone app, and seeing what I can do with it. For most of my variables, I simple store them as "int" or "float" or whatnot. However, when I have to pass an object (Such as in a Dictionary) then I need them as an Object. I use NSNUmber. This is how I initialize the object. NSNumber *testN...

Storing ints in a Dictionary

As I understand, in Objective-C you can only put Objects into dictionaries. So if I was to create a dictionary, it would have to have all objects. This means I need to put my ints in as NSNumber, right? SOo... NSNumber *testNum = [NSNumber numberWithInt:varMoney]; NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] i...

How to convert NSNumber objects for computational purposes?

I an developing some code in which I use a scanner to get to NSNumbers from a string, say x and y. Now I want to compute something simple from x and y, say, z = 10.0/(x + y/60.0)/60.0). I can't do this directly, since the compiler doesn't like ordinary arithmetic symbology applied to number objects. So, I tried defining xD and yD, of t...

Cast as an NSNumber doubleValue adding extra [phantom] precision

iPhone sdk 3.2.1 NSMutableDictionary *myDict = [NSMutableDictionary dictionaryWithCapacity:2]; [myDict setObject:[NSNumber numberWithDouble:0.1f] forKey:@"testDoubleObject"]; [myDict setValue:[NSNumber numberWithDouble:0.1f] forKey:@"testDoubleValue"]; Printing the description of myDict to the console yields this: Printing descrip...

Roundtripping double to text and back

Using Cocoa or basic c, how can I convert a double to a string representation and then convert it back to the exact same double. Readability is not important, only accuracy. For example, will this work: double a,b; a=some value; b=[[[NSNumber numberWithDouble:a] stringValue] doubleValue]; ...

How can I prevent myself from accidentally using an NSNumber's pointer when I want its intValue?

One feature of Java that I really like is autoboxing, in which the compiler automatically converts between primitives and their wrapper classes. I'm writing a Core Data application in Objective-C/Cocoa, and I'm finding it frustrating to deal with my integer attributes programmatically. Here's why: //img is a managed object that I have ...

NSArray of UIBarButtonItem Tag (i.e. NSInteger)

Is it true that you can't have an NSMutableArray of NSIntegers? When I try to add the values to the array and then print them out they're huge numbers (when if I print out the tag to NSLog they're 0,1,2,3 etc.). I'm trying to create an array of my UITabBarItem's tags so I can save the order and retrieve it later. Am I forced to do some ...

Best way to handle persistent Boolean in plist?

What's the best way to handle Boolean values that derive from a UISwitch setting, and are stored in an NSMutableDictionary that is saved to the user's directory as persistent settings? Specifically, what's the best way to keep boolean values distinct from numeric values in an NSMutableDictionary that gets written to and read from the fil...

Retreive NSNumber From Array

Hi, I am relatively new to Objective C and need some array help. I have a plist with which contains a Dictionary and an NSNumber Array, with more arrays to be added later on. NSMutableDictionary *mainArray = [[NSMutableDictionary alloc]initWithContentsOfFile:filePath]; NSArray *scoresArray = [mainArray objectForKey:@"scores"]; I ne...

Trying to NSLog an NSNumber ivar in an instance method

Hello, I'm working on a console app that is tracks different songs. I'm working on getting the song class up off the ground first and have run into a snag trying to log an nsnumber which has been allocated for the song duration into an nslog statement: // // Song.h // MusicCollection.15.9 // // Created by Nicholas Iannone on 1/11...

Wondering how to deal with nsnumber objects in an arithmatic operation

I saw this thread but wanted to confirm: http://stackoverflow.com/questions/1801197/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 pai...

NSNumber numberWithInt: returns strange numbers?

I am just starting out with Core Data and ran into an issue where I need to save the new object with the appropriate ID. I'm trying to add the next number in the row as an ID for the object the user adds: NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:[NSEntityDescription entityForName:@"Favorites" inManage...

Type casting for Core Data attribute setting

I am trying to set a Core Data attribute but am getting incompatible type errors. I have a float attribute in a Core Data entity on iPhone 3.0. Core Data auto-generates an interface for a managed data object that provides property access to it: @property (nonatomic, retain) NSNumber * volume; and an implementation for it: @dynamic vo...

NSFileSystemFreeSize

Hi, I get a negaitve number from trying to use this function can anyone help. see code below NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:dbPath error:Error]; NSDictionary *fileSysAttributes = [fileManager fileSystemAttributesAtPath:dbPath]; NSNumber *FileSize = [fileAttributes objectForKey:NSFileSize]; NSNumber...

How to read crash log? How to find why the app crashes in system library? What means EXC_CRASH (SIGABRT)?

I got an crash logs from a customer to figure why my app crash on her iPhone. Here some info from crash log: Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x00000000, 0x00000000 Crashed Thread: 0 Stack trace for Thread 0 Thread 0 Crashed: 0 libSystem.B.dylib 0x3293f98c 0x328c1000 + 518540 1 libSystem.B.dy...

Hard crash using [NSDecimalNumber stringValue]

Hello, My app crash when I try to access any property of my NSDecimalNumber amount_before_current_year: [amount_before_current_year stringValue] Program received signal: “EXC_BAD_ACCESS”. The object is a NSDecimalNumber as shown in the image attached. I created it in the viewDidLoad, it exists in the header file: .h ... NSDeci...

How to convert NSNumber to NSInteger

How to convert an NSNumber to NSInteger ? ...