• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSXMLParser attributeDict enumeration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSXMLParser attributeDict enumeration


  • Subject: Re: NSXMLParser attributeDict enumeration
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 27 Apr 2009 10:05:03 -0700

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSXMLParser attributeDict enumeration
      • From: Martijn van Exel <email@hidden>
References: 
 >NSXMLParser attributeDict enumeration (From: Martijn van Exel <email@hidden>)

  • Prev by Date: Current thinking on [NSView allocateGState] ?
  • Next by Date: Re: figuring out which TableView I am?
  • Previous by thread: Re: NSXMLParser attributeDict enumeration
  • Next by thread: Re: NSXMLParser attributeDict enumeration
  • Index(es):
    • Date
    • Thread