On Apr 27, 2009, at 08:10, Martijn van Exel wrote:

currentNode.lat = (double)[attributeDict objectForKey:key];
...
Member 'lat' is a double. The above does not work. 'Pointer value used where
float was expected'. So I should dereference?

currentNode.lat = (double *)[attributeDict objectForKey:key];

"Dereference" is the wrong word. What you actually did was *cast*, but that was the wrong thing to do anyway.

The result of [attributeDict objectForKey:key] is always an object pointer (id, NSString*, NSNumber*, etc), never a scalar (int, double, etc). There are three possibilities here:

1. It's a NSNumber object, in which case you'd use:

        currentNode.lat = [[attributeDict objectForKey:key] doubleValue];

2. It's a NSString object, and you're certain that it contains a well- formatted numeric representation, in which case you'd use NSString's convenience method:

        currentNode.lat = [[attributeDict objectForKey:key] doubleValue];

3. It's a NSString object, and you're *not* certain that it contains a well-formatted numeric representation, in which case you can use NSScanner's scanDouble: on the string to retrieve the number and then check that there are no characters left over.

Of course, if the object is none of the above, we can't tell you how to get a double out of it.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to