Re: NSString propertyList crash
Re: NSString propertyList crash
- Subject: Re: NSString propertyList crash
- From: Greg Herlihy <email@hidden>
- Date: Sun, 19 Mar 2006 22:07:59 -0800
- Thread-topic: NSString propertyList crash
NSDictionary's description and propertyList methods are not perfect inverse
operations - specifically all NSDate values in the original dictionary
become NSString values when the dictionary is reconstituted from the
description string.
This kind of information loss should not be unexpected, however, because a
"description" of an object is not a serialization or an archive of that
object (but merely its string representation). In other words, there is no
guarantee that an object's description can ever be used to recreate the
object it describes exactly (it may or may not). Instead, in order to store
and recreate a an object with 100% fidelity really requires methods that
explicitly serialize (and unserialize) its contents. And since
NSPropertyListSerialization provides exactly those kinds of methods for
property lists, it is the most appropriate class to use in this situation.
Greg
On 3/19/06 9:30 PM, "Andy Lee" <email@hidden> wrote:
> On Mar 19, 2006, at 11:39 PM, Tito Ciuro wrote:
>> Hi Andy,
>>
>> That works fine. :-)
>
> Greg Herlihy's approach, using +dataWithContentsOfFile:, might be
> safer, given what he said about binary plist files.
>
>> Just for completeness, adding the following statement will convert
>> the NSString to a dictionary:
>>
>> NSDictionary *newDict = [dictXML propertyList];
>> NSLog(@"newDict: %@", newDict);
>
> Interesting -- the doc for -propertyList doesn't say anything about
> being able to parse XML. In fact, it describes a syntax that is
> definitely *not* XML. I guess it's smart enough to tell which format
> it's looking at. I sent feedback about this using the link at the
> bottom of the NSString page.
>
> On Mar 19, 2006, at 11:40 PM, Tito Ciuro wrote:
>> On 19/03/2006, at 20:31, Andy Lee wrote:
>>> NSDictionary *dict =
>>> [NSDictionary dictionaryWithObjectsAndKeys:
>>> [NSDate date], @"today",
>>> nil];
>>> NSString *desc = [dict description];
>>> NSDictionary *newDict = [desc propertyList]; // throws exception
>>
>> It sure looks like a bug to me...
>
> I looked closer at the docs and they don't explicitly say the two
> methods are supposed to be mirror images, but it's implied strongly
> enough that I think it's clearly a bug. The exception also gets
> raised if you use the StringsFileFormat methods.
>
> I was about to report this, but bugreport.apple.com is not letting me
> log in right now.
>
> --Andy
>
> _______________________________________________
> 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
_______________________________________________
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