nosuic
nosuic

Reputation: 1360

Simple: NSArray object to Double?

I have a NSArray with numbers and I want to get the value of an item of the array and assign it to a double. In my attempt of simple casting:

lat = (double)[storesList.latitudes objectAtIndex:i];

I get the error: "Pointer value used where a floating point value was expected".

Please help!

Thank you,

F.

Upvotes: 6

Views: 5523

Answers (3)

Radix
Radix

Reputation: 3657

You can use this code

double lat = [[storeList.latitudes objectAtIndex:i] doubleValue];

Thank you

Upvotes: 2

Oleg Danu
Oleg Danu

Reputation: 4159

If you say that your array is consisting of number (NSNumber class), that you may should get the value next way:

double lat = [[storeList.latitudes objectAtIndex:i] doubleValue];

Upvotes: 15

BoltClock
BoltClock

Reputation: 723598

You cannot cast an NSNumber object to a primitive double type value. Use the doubleValue method of NSNumber instead, like this:

lat = [[storesList.latitudes objectAtIndex:i] doubleValue];

Upvotes: 7

Related Questions