Re: NSString propertyList crash
Re: NSString propertyList crash
- Subject: Re: NSString propertyList crash
- From: Ed Baskerville <email@hidden>
- Date: Mon, 20 Mar 2006 01:07:35 -0800
Hi all,
I see two problems going on here. One, the documentation is
misleading: description methods are designed to generate human-
readable debugging output, not to serialize data. Two, despite this,
the description method really should generate valid property lists,
even though those plists won't be able to recreate the original
object graph if any non-plist objects are present. I submitted bugs
on both.
The long version:
(1) Problems with the documentation
The description of NSDictionary's description method is as follows:
Returns a string that represents the contents of the receiver,
formatted as a property list.
It's easy to jump to the conclusion that this would mean that you can
use the description method to generate an old-school ASCII property
list, and then parse that property list to get back the original
dictionary.
However, ASCII property lists only support four types:
ASCII property lists support the four primary property list data
types: NSString (java.lang.String in Java), NSData, NSArray, and
NSDictionary. Additionally, NSDate and NSNumber objects can be
archived, but will become strings when unarchived.
(from http://developer.apple.com/documentation/cocoa/Conceptual/
PropertyLists/Concepts/OldStylePListsConcept.html)
So you definitely can't count on the description method to create
NSDates and NSNumbers that can be parsed (although this implies that
you should be able to recreate them *as strings*). Furthermore, you
can call description on any dictionary you want, even if it contains
objects from non-plist classes--in that case, you definitely won't be
getting back the original objects by parsing the description.
In short, the documentation needs to emphasize that description
methods are intended only for generating human-readable debugging
output, NOTHING ELSE. As mentioned before, you should be using
NSPropertyListSerialization for real serialization/deserialization of
data.
I've filed bug #4483656 ("NSDictionary/NSArray description methods
documentation is misleading") suggesting a rewording: "Returns a
string that describes the contents of the receiver, formatted as an
ASCII property list. This method is intended for debugging purposes,
not for serializing data. If you want to store data for later
retrieval, see [references to archiving and info on
NSPropertyListSerialization]."
(2) Bug in the description method
Even though it's not going to generate property lists that parse to
the original object graph unless that graph contains only NSString,
NSData, NSArray, and NSDictionary objects, it should generate valid
property lists. It looks like it's just a matter of making sure
strings are wrapped in double quotes if they need to be.
I checked that this is fact not just a problem with NSDate: it
happens with any object that generates a description with spaces in
it. It affects NSArray's description method as well.
Greg, since I was looking at this anyway, I went ahead and submitted
bug #4483658 ("NSDictionary/NSArray description methods produce
invald plists").
--Ed
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden