Search code examples
objective-cxcode4

How can I typecast an NSArray element to double?


An other way please.
I have an array whole elements are doubles. How can I get the content out as double?e.g.

coordinate.latitude = [coords objectAtIndex:0];// value inside it is 61.2180556;

Solution

  • You can't store primitive doubles in NSArray. You have either stored them as NSNumber or NSString. In either case use:

    coordinate.latitude = [[coords objectAtIndex:0] doubleValue];