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.
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.
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.
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...
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 .
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];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With