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
28
votes
4 answers

Comparing two NSNumber objects

I used this code to compare two NSNumber objects, but it never passed the if condition. listItems = [appDelegate.productStatus componentsSeparatedByString:@","]; for (int i=0;i<[appDelegate.productArray count]; i++) { for (int j=0;…
USK
  • 499
  • 1
  • 4
  • 9
26
votes
2 answers

Using setValue(value, forKey: key) on Int? types fires non key value coding-compliant method

I'm successfully using the setValue(value, forKey: key) method in my NSKeyValueCoding compliant Swift NSObject subclass. This works perfectly well on String optionals, e.g. var name:String? However, on Int optionals, it fails, triggering the…
Max MacLeod
  • 26,115
  • 13
  • 104
  • 132
26
votes
6 answers

How get the total sum of NSNumber's from a NSArray?

I have a large NSArray containing NSNumbers like 3, 4, 20, 10, 1, 100, etc... How do I get the total sum of all these NSNumbers (3 + 4 + 20 + 10 + 1 + 100 + etc...) as one total NSInteger? Thank you!
neowinston
  • 7,584
  • 10
  • 52
  • 83
24
votes
7 answers

Why is NSNumber immutable?

Why is NSNumber immutable? Was there a good reason? Because now I am thinking about creating my own class just for the sake of mutability.
Proud Member
  • 40,078
  • 47
  • 146
  • 231
24
votes
1 answer

Storing and retrieving unsigned long long value to/from NSString

I have an unsigned long long value which I want to store into an NSString and retrieve from the string. Initially I have the value in an NSNumber and I am using this to get the string NSString *numStr = [NSString stringWithFormat:@"%llu", [myNum…
lostInTransit
  • 70,519
  • 61
  • 198
  • 274
23
votes
4 answers

How to convert NSNumber to String in Swift4?

How to convert an Array of NSNumber to Array of String in order to display the value in UITableView? cell.textlabel.text = ? Code: var a = [68.208983, 6.373902, 1.34085, 3.974012, 110.484001, 61.380001, 1.325202, 0.8501030000000001,…
SDK
  • 1,356
  • 3
  • 19
  • 44
23
votes
7 answers

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…
Mustafa
  • 20,504
  • 42
  • 146
  • 209
23
votes
4 answers

Comparing NSNumber to 0 not working?

I have a JSON parser in my app, and I load the value into a detailDataSourceDict variable. When I try to get the valueForKey of the array and try to compare it to 0, it never works... Here's my code: if (indexPath.row == 1) { NSNumber *rating =…
1789040
  • 569
  • 2
  • 6
  • 17
22
votes
3 answers

What is the class NSCFNumber in iOS 4.1?

After successfully acquiring a picture from the iPhone camera on iOS 4.1, you can use the key @"UIImagePickerControllerMediaMetadata" to return information about the picture. One of the keys in that dictionary is @"Orientation" From my…
Daddy
  • 9,045
  • 7
  • 69
  • 98
20
votes
5 answers

Compare a NSNumber to an int

I've a simple question (I think): I'm trying to compare a NSNumber with a int, to see if it is 0 or 1. Here is the code: id i = [dictionary objectForKey:@"error"]; //class = NSCFNumber NSLog(@"%@ == 0 -> %@", i, i == 0); NSLog(@"%@ == 0 -> %@", i,…
patrick
  • 6,533
  • 7
  • 45
  • 66
20
votes
4 answers

@"" 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…
rob5408
  • 2,972
  • 2
  • 40
  • 53
20
votes
4 answers

NSString To NSNumber

So this problem has been perplexing me for way too long. I have a UIAlertView with a textField in it, and I need the value of the textField as an NSNumber. But everything I try gives me random strings of numbers. Any help would be very much…
Andrew
  • 3,874
  • 5
  • 39
  • 67
19
votes
5 answers

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…
testing
  • 19,681
  • 50
  • 236
  • 417
19
votes
3 answers

Is there a correct way to determine that an NSNumber is derived from a Bool using Swift?

An NSNumber containing a Bool is easily confused with other types that can be wrapped in the NSNumber class: NSNumber(bool:true).boolValue // true NSNumber(integer: 1).boolValue // true NSNumber(integer: 1) as? Bool // true NSNumber(bool:true) as?…
sketchyTech
  • 5,746
  • 1
  • 33
  • 56
18
votes
5 answers

React Native - NSNumber cannot be converted to NSString

Below is part of my react component. I have a props named daysUntil coming into this component which contains a number. In this example it is being pass the number 0 which results in the fontWeight function returning 700 render: function() { …
Sohrab Hejazi
  • 1,441
  • 6
  • 18
  • 29
1
2
3
52 53