Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 221
nosuic Avatar asked Dec 30 '10 11:12

nosuic


People also ask

How do I create an NSArray in Objective-C?

Creating NSArray Objects Using Array Literals In addition to the provided initializers, such as initWithObjects: , you can create an NSArray object using an array literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method.

What is difference between NSArray and NSMutableArray?

The primary difference between NSArray and NSMutableArray is that a mutable array can be changed/modified after it has been allocated and initialized, whereas an immutable array, NSArray , cannot.

Is NSArray ordered?

The answer is yes, the order of the elements of an array will be maintained - because an array is an ordered collection of items, just like a string is an ordered sequence of characters...

What is NSMutableArray?

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray .


2 Answers

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];
like image 98
Oleg Danu Avatar answered Sep 20 '22 02:09

Oleg Danu


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];
like image 32
BoltClock Avatar answered Sep 22 '22 02:09

BoltClock