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
9
votes
5 answers

Is NSNumber overkill for an instance-level counter?

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,…
Rich
  • 36,270
  • 31
  • 115
  • 154
9
votes
2 answers

setProgress is no longer updating UIProgressView since iOS 5

I have a little trouble with a progress bar since iOS 5 came out. The code below was working fine before iOS 5 but with iOS 5 the progress bar is no longer displaying the new progress that is set within a loop. The code is expected to work like…
favo
  • 5,426
  • 9
  • 42
  • 61
9
votes
4 answers

Loss of precision converting 'float' to NSNumber, back to 'float'

I seem to be encountering a strange issue in Objective-C converting a float to an NSNumber (wrapping it for convenience) and then converting it back to a float. In a nutshell, a class of mine has a property red, which is a float from 0.0 to…
Craig Otis
  • 31,257
  • 32
  • 136
  • 234
9
votes
4 answers

Detecting if NSNumber is between 0 and 255

I am trying to detect whether a NSNumber is between 0 and 255 or not. Whenever I run the app, I receive the alert view that my number is greater than 255, even when it is not. I do not have this problem with 0. if (redValue < 0) { NSLog(@"Red…
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
9
votes
5 answers

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 objective-c?
node ninja
  • 31,796
  • 59
  • 166
  • 254
9
votes
1 answer

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 ||…
user439407
  • 1,666
  • 2
  • 19
  • 40
9
votes
2 answers

Convert NSNumber to NSTimeInterval in Swift

I'm stuck with some sort of casting in Swift as I am very new to Swift. Here is my code: if let matchDateTime = item["matchDate"].number { _matchDateTime=matchDateTime } println(_matchDateTime) let date =…
BeingShashi
  • 159
  • 1
  • 3
  • 11
9
votes
1 answer

Accessing boolValue in a NSNumber var with optional chaining (in Swift)

I have a NSManagedObject subclass with an optional instance variable @NSManaged var condition: NSNumber? // This refers to a optional boolean value in the data model I'd like to do something when the condition variable exists and contains…
Zaggo
  • 786
  • 1
  • 6
  • 14
9
votes
5 answers

How do you get the int and modulo (mod) of division with an NSDecimalNumber

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…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
8
votes
5 answers

How do you store "int" values in an NSMutableArray* or NSMutableDictionary*? Chronic problems with JSON data that come in as integers.

How do you store "int" values in an NSMutableArray or NSMutableDictionary? Chronic problems with JSON data that come in as integers. Should I try to store these integers as NSNumber objects or just as strings that contain the integer? How…
MikeN
  • 45,039
  • 49
  • 151
  • 227
8
votes
3 answers

Why NSNumber points to the same address when value are equals?

Given the following code: int firstInt, secondInt; firstInt = 5; secondInt = 5; NSNumber *firstNumber = [NSNumber numberWithInt:firstInt]; NSNumber *secondNumber = [NSNumber numberWithInt:secondInt]; Why on Earth do those two NSNumber instances…
jchatard
  • 1,881
  • 2
  • 20
  • 25
8
votes
4 answers

NSPredicate, NsNumber numberWithFloat:0.0 (iPhone)

hi i have Core Data database with numerical attributes. they are NSNumbers. Default value is 0.0 but when i try to do some NSPredicated fetch, i get "'NSInvalidArgumentException', reason: 'Invalid predicate: nil RHS'" just because attribute value is…
Greg
  • 83
  • 2
  • 4
8
votes
1 answer

What's the largest value an NSNumber can store?

What's the largest value an NSNumber can store? // ok NSNumber *value = @(1 << 31); // gives compiler error, so max NSNumber is 32-bit uint? NSNumber *value = @(1 << 32);
Boon
  • 40,656
  • 60
  • 209
  • 315
8
votes
3 answers

Storing optional NSNumber in Core Data

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…
mmc
  • 17,354
  • 2
  • 34
  • 52
7
votes
4 answers

NSNumber compare: returning different results

I'm trying to do some number comparisons and I'm getting some weird results. NSNumber* number1 = [NSNumber numberWithFloat:1.004]; NSNumber* number2 = [NSNumber numberWithDouble:1.004]; ([number1 compare:number2] == NSOrderedSame) ? NSLog(@"YES") :…
Matt W.
  • 956
  • 9
  • 21