nsnumber

NSNumber Warning when using setter but code seems to work OK - Passing argument 1 makes integer from pointer without a cast

I have an object Foo that has an NSNumber property which is declared like this: @property (retain) NSNumber *siteID; and @synthesized. When I I do something like this: Foo *myFoo = [[Foo alloc] init]; NSNumber *newNumber = [[NSNumber alloc] initWithInt:42]; myFoo.siteID = newNumber; [newNumber release]; The assignment on line 3 th...

Convert NSString to double for calculations and then back again to print in NSString

I accept NSString as NSString *value = [valuelist objectAtIndex:valuerow]; NSString *value2 = [valuelist2 objectAtIndex:valuerow2]; from UIPickerView. I want to double *cal = value + (value2 * 8) + 3; NSString *message =[[NSString alloc] initWithFormat:@"%@",cal]; I should be able to get the string in message after I do the calc...

NSNumber intValue giving EXC_BAD_ACCESS

I have an NSNumber being passed to be via a 3rd party API, and when I call intValue on the index I get a EXC_BAD_ACCESS error: -(CPFill *) barFillForBarPlot:(CPBarPlot *)barPlot recordIndex:(NSNumber *)index; { NSLog(@"bar index %i", index); int value = [index intValue]; } The output I get in the debugger is: bar index 0 ba...

NSPredicate: Search on NSNumber (Cocoa)

Hi all, I have an Cocoa Core-Date Application. I added a search field and bound it. Now, I have tried to add some predicates but failed! Here are my two questions: First, the predicate should filter NSNumbers but I cannot build a working predicate. My try: keyPath == [NSNumber numberWithInteger:[$value integerValue]] (keyPath repre...

Should I use NSNumber or an int in an iPhone/iPad class?

I'm creating an object that will have two integers (or NSNumbers) and an NSDate as ivars. This object will be in an NSMutableArray. To my knowledge, we cannot put primative integers in an NSMutableArray, but will my object work with ints? The reason I don't want to use NSNumbers is because these will have to be mutable, and I don't reall...

Correctly convert NSString to NSnumber

Hi guys, I can't figure out why it's not working, I have a NSString which I need to convert to NSNumber (to save it to Core Data) e.g NSLog(stringNum); returns 1 NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; [f setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber *myNumber = [f numberFromString:stringNum]; [f releas...

create timestamp of now as NSNumber in objective-c

Hi everyone, how can I get timestamp as NSNumber? I only need something like this: 1232885280 Thanks ...

Formatting number as percentage

I don't understand how NSNumberFormatterPercentStyle works! Example: NSNumber *number = [NSNumber numberWithFloat:90.5]; NSNumberFormatter *percentageFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [percentageFormatter setNumberStyle:NSNumberFormatterPercentStyle]; NSString *strNumber = [percentageFormatter stringFromNumbe...

Adding data to an NSDictionary... SRSLY? Isn't there a quicker way?

I'm from a Flash ActionScript background. Where I'm from, I can set a dictionary-like object like this: var data:Object = {startPoint:5, endPoint:12}; So coming to Objective-C, I was surprised to discover that the equivalent to this appears to be: NSMutableDictionary *data = [NSMutableDictionary dictionary]; [data setObject:[NSNumber...

how to convert NSNumber to int in Objective-C

Before putting int value into dictionary i have set the int value as [NSNumber numberWithInt:2], now when i try to retrieve back the dictionary content , i want it back in int format.. hw to do this?? here's my code; NSMutabelDictionary *dict = [[NSMutableDictionary alloc]init]; int intValue = 300; [dict setObject:[NSNumber numberWith...

Why isn't the NSNumber class correctly converting my NSString object to a long long?

Hello. I'm trying to convert an NSString object to an NSNumber with the same numerical value. When I create the NSString object using this statement... NSString *songID = [localNotif.userInfo objectForKey:@"SongID"]; the var songID contains the string value @"10359537395704663785". and when I attempt to convert it to an NSNumber ob...

How can I get an NSNumber without performing alloc on it, so it will respond to initWithInt?

My understanding is that a 'convenience' method such as [nsnumber initWithInt] should create a copy of the indicated class, initialized to the desired value. minutesLeft=[NSNumber initWithInt:((timeLeft)%60)]; Timeleft is an integer, so initWithInt should be working, and the result should be that minutesLeft (a property set to retain)...

iPhone: Problem with incrementing NSNumber & displaying transparent images (UIImageView)

Hi Guys! I have a problem with NSNumber: I don't understand how to increment and decrement it! I've tried int with [NSNumber intValue] and so on, but it didn't work!!!! I just want a page counter which can be converted to an NSNumber at the end. My second problem is displaying a (partially) transparent image in an UIImageView. It has e...

Convert NSString to NSNumber

Hi, i get a nsstring from a nsdictionary via: inputString = [dataUsage valueForKey:@"amount"]; after that the string looks like: 23,56 how can i convert this string into a nsnumber? i have tried the following: NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle];...

53 * .01 = .531250

I'm converting a string date/time to a numerical time value. In my case I'm only using it to determine if something is newer/older than something else, so this little decimal problem is not a real problem. It doesn't need to be seconds precise. But still it has me scratching my head and I'd like to know why.. My date comes in a strin...

check if NSNumber is empty

How do I check if a NSNumber object is nil or empty? OK nil is easy: NSNumber *myNumber; if (myNumber == nil) doSomething But if the object has been created, but there is no value in it because an assignment failed, how can I check this? Use something like this? if ([myNumber intValue]==0) doSomething Is there a general met...

Issue with NSNumber -initWithDouble and resulting values

Hi all, I'm using NSNumber to store various values, but sometimes run into issues when doing calculations with the values and initializing new NSNumber objects for the results. I've figured out how to overcome it, but I couldn't for the life of me explain why it works and since my grasp on numerical values in computer environments (doub...

Converting (u)int64_t to NSNumbers

So essentially my question is this, I am creating an NSMutableDictionary using uint64_t objects as the key. Is there any better way to create them than doing this? uint64_t bob=7; NSNumber *bobsNumber; #if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 bobsNumber=[NSNumber numberWithUnsig...

@"" string type literals for NSNumber

I love the shorthand handling of string literals in Objective C with the @"string" notation. Is there any way to get similar behavior with NSNumbers? I deal with numbers more and it's so tedious having [NSNumber numberWithWhatever:] calls everywhere. Even creating a macro would work, but my knowledge of how best to do that is limited. ...

Generating permutations of NSArray elements

Let's say I have an NSArray of NSNumbers like this: 1, 2, 3 Then the set of all possible permutations would look something like this: 1, 2, 3 1, 3, 2 2, 1, 3 2, 3, 1 3, 1, 2 3, 2, 1 What's a good way to do this in XCode? ...