Questions tagged [nsnumber]

on Mac OS X, NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type

NSNumber is a subclass of NSValue that offers a value as any C scalar (numeric) type. It defines a set of methods specifically for setting and accessing the value as a signed or unsigned char, short int, int, long int, long long int, float, or double or as a BOOL. (Note that number objects do not necessarily preserve the type they are created with.)

Resource

785 questions
18
votes
4 answers

NSNumber constants in Obj-C

I want to make some NSNumber constants via the same style used for NSStrings in this topic. That is, I'm creating separate constants.h/.m files and importing them into classes that need to access them.
DrWurm
  • 185
  • 1
  • 1
  • 4
17
votes
1 answer

how do I set the value of an NSNumber variable (without creating a new object) in objective-c

how do I set the value of an NSNumber variable (without creating a new object) in objective-c? Background I'm using Core Data and have a managed object that has an NSNumber (dynamic property) passing (by reference) this to another method which will…
Greg
  • 34,042
  • 79
  • 253
  • 454
16
votes
6 answers

Check if NSArray contains some int

I have a NSMutableArray of NSNumbers. Basically I just want to check if any of the NSNumbers in the array = some value. I could iterate through the array, checking one by one, by this is by no means optimal. I also tried and failed using…
Henry
  • 183
  • 1
  • 1
  • 4
16
votes
1 answer

converting double into NSNumber using [NSNumber numberWithDouble:]

there is a coordinate object with three variables latitude(NSNumber) ,longitude(NSNumber) and time(NSDate),for checking the program on my simulator,i gave the folowing code [coordinate setLatitude:[NSNumber numberWithDouble:23.234223]]; [coordinate…
sujith1406
  • 2,822
  • 6
  • 40
  • 60
16
votes
6 answers

Objective c: Check if integer/int/number

In objective c, how can i check if a string/NSNumber is an integer or int
Daniel
  • 3,017
  • 12
  • 44
  • 61
16
votes
4 answers

Convert NSNumber (double) value into time

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!
phx
  • 5,927
  • 4
  • 24
  • 24
15
votes
2 answers

How to cast from UInt16 to NSNumber

I have a UInt16 variable that I would like to pass to a legacy function that requires an NSNumber. If I try: var castAsNSNumber : NSNumber = myUInt16 I get a compiler error 'UInt16' is not convertible to 'NSNumber' Question How can I recast this as…
PassKit
  • 12,231
  • 5
  • 57
  • 75
15
votes
3 answers

Adding Integer To NSMutableArray

I couldn't find this anywhere, so I am asking just asking to make sure. And yes, I know its basic, but I figure I'd rather get that right before I make the mistake a million times: If I do the following, does it cast the "0" to an NSNumber by…
MrHappyAsthma
  • 6,332
  • 9
  • 48
  • 78
15
votes
2 answers

How to convert typedef enum to NSNumber?

Is each value of a typedef enum treated as an int? E.g., given the following typedef enum: // UIView.h typedef enum { UIViewAnimationCurveEaseInOut, UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, …
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
14
votes
3 answers

Objective-C Converting an integer to a hex value

I've got a dictionary initialized like so... keyDictionary = [[NSDictionary dictionaryWithObjects:values forKeys:keys]retain]; where keys is an NSArray of the alphabet and other characters and values is an NSArray of unsigned chars, which are the…
DavidAndroidDev
  • 2,371
  • 3
  • 25
  • 41
14
votes
3 answers

How to convert string with number to NSDecimalNumber that has a comma not a decimal point?

I have an interface giving me numbers like this 0000000012345,78 So i figured out how to make a number out of them. But I need to calculate with that number and what I actually need is a decimal number. NSNumberFormatter *fmtn = [[NSNumberFormatter…
hol
  • 8,255
  • 5
  • 33
  • 59
14
votes
1 answer

Trying to NSLog an NSNumber ivar in an instance method

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…
nickthedude
  • 4,925
  • 10
  • 36
  • 51
14
votes
1 answer

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…
John R Doner
  • 2,242
  • 8
  • 30
  • 36
13
votes
3 answers

NSNumber from NSDate

I'm attempting to get around a date validation that refuses to take anything earlier than tomorrow. So far I have this: NSDate *dateY = [NSDate dateWithTimeIntervalSinceNow:-86400]; // Negative one day, in seconds…
Thromordyn
  • 1,581
  • 4
  • 17
  • 45
13
votes
4 answers

iOS - Why Does It Work When I Compare Two NSNumbers With "=="?

In my app, I accidentally used "==" when comparing two NSNumber objects like so: NSNumber *number1; NSNumber *number2; Later on, after these objects' int values were set, I accidentally did this: if (number1 == number2) { NSLog(@"THEY'RE…
Rafi
  • 1,902
  • 3
  • 24
  • 46
1 2
3
52 53