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

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]…
Omkar Jadhav
  • 1,046
  • 3
  • 16
  • 41
13
votes
2 answers

Swift: CInt to Int conversion?

What is the most concise way to convert a CInt to an Int (the native integer type) in Swift? Right now I'm using: NSNumber.numberWithInt(myCInt).integerValue Is this the preferred approach?
jhurliman
  • 1,790
  • 1
  • 18
  • 20
13
votes
5 answers

how can i check NSNumber is null?

NSDictionary *regionDict = (NSDictionary *) region; NSNumber *lat = [regionDict objectForKey:@"lat"]; //[latitude addObject:lat]; NSNumber *lng = [regionDict objectForKey:@"lng"]; //[longitude…
Priyank Gandhi
  • 626
  • 2
  • 8
  • 21
13
votes
3 answers

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…
Ethan Mick
  • 9,517
  • 14
  • 58
  • 74
12
votes
2 answers

Converting Double to NSNumber in Swift Loses Accuracy

For some reason, certain Doubles in my Swift app are giving me trouble when converting to NSNumber, while some are not. My app needs to convert doubles with 2 decimal places (prices) to NSNumbers so they can be stored and retrieved using Core Data.…
joelrorseth
  • 123
  • 1
  • 1
  • 7
12
votes
5 answers

How to convert Swift optional NSNumber to optional Int? (any improvements on my code?)

What would be the shortest/cleanest way to convert an Optional Number to an Optional Int in Swift? Is there a better way than this? (see below) let orderNumberInt : Int? if event.orderNum != nil { orderNumberInt = Int(event.orderNum!) } else…
Greg
  • 34,042
  • 79
  • 253
  • 454
12
votes
4 answers

iOS Implicit conversion of int to NSNumber is disallowed with ARC

on following code i'm get the errormessage: Implicit conversion of 'int' to 'NSNumber *' is disallowed with ARC. What i'm making wrong?
 
  NSDictionary *results = [jsonstring JSONValue];
  NSNumber *success = [results…
Daniel
  • 123
  • 1
  • 1
  • 5
11
votes
2 answers

Objective-C - ARC - NSNumber - Segmentation Fault

I have an objective-C program and I am using ARC (Automatic Reference Counting), it throws a segmentation fault in line 23 (see program below). Question 1) Why does the segmentation fault occur ? Given below is the…
11
votes
3 answers

How to add numbers in a mutable array in iPhone?

I am new to iPhone development. I want a Nsmutable array to hold numbers from 1 to 100. How can I do it? How can I implement in a for loop? Is there any other way to hold numbers in array in iPhone?
Warrior
  • 39,156
  • 44
  • 139
  • 214
11
votes
2 answers

NSNumber from CGFloat

Is there a safe way to "convert" a CGFloat to a NSNumber ? NSNumber has the numberWithFloat: and numberWithDouble: methods but CGFloat being defined as float or double depending on the platform, it seems risky to use either one of them. Or is…
Guillaume Algis
  • 10,705
  • 6
  • 44
  • 72
10
votes
3 answers

NSNumber vs Int

If integers cannot be written to a dictionary and then to a .plist, but NSNumbers can is it better to use NSNumbers throughout the app, rather than needing to convert every-time saving or loading a dictionary from a .plist?
user773578
  • 1,161
  • 2
  • 13
  • 24
10
votes
2 answers

NSNumber vs Int, Float in Swift Dictionary

According to Swift 3 documentation, NSNumber is bridged to Swift native types such as Int, Float, Double,...But when I try using a native type in Dictionary I get compilation errors that get fixed upon using NSNumber, why is that? Here is my code…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
10
votes
1 answer

Does NSNumberFormatter.stringFromNumber ever return nil?

It seems to me that any valid number can also be expressed as a String, so I don't know why this function returns a String? instead of a String.
m81
  • 2,217
  • 5
  • 31
  • 47
10
votes
2 answers

Collection element of type 'double' is not an Objective-C object

The inY property gives an error. What is the correct syntax? UIButton *optionButton = [UIButton buttonWithType:UIButtonTypeCustom]; NSObject* anim = @{@"target": target, @"inY": infoView.frame.size.height-100, @"outY": @800}; Tried creating a…
springbo
  • 1,096
  • 1
  • 9
  • 15
10
votes
3 answers

How to do math on NSNumber

I am trying to take a reading off a sensor and display it as a percentage. [some value] will always be between 0 and 1. Here is my code: NSNumber *reading = [some value]; reading = [reading floatValue] * 100; However, I get "Assigning to NSNumber…
sdknewbie
  • 659
  • 2
  • 9
  • 13