Re: NSString propertyList crash
Re: NSString propertyList crash
- Subject: Re: NSString propertyList crash
- From: Greg Herlihy <email@hidden>
- Date: Sun, 19 Mar 2006 20:01:36 -0800
- Thread-topic: NSString propertyList crash
There is no bug here: an NSDictionary object cannot be initialized with a
binary plist file.
For that reason, I would use NSPropertyListSerialization to create an
NSDictionary from a plist, since it understands the various plist file
formats:
NSString *dirPath = [@"~/Library/Preferences/com.apple.Bluetooth.plist"
stringByExpandingTildeInPath];
NSData *contents = [NSData dataWithContentsOfFile:dirPath];
NSString *errorString;
NSPropertyListFormat format;
NSDictionary *dict = [NSPropertyListSerialization
propertyListFromData:contents
mutabilityOption:NSPropertyListImmutable format:&format
errorDescription:&errorString];
Greg
On 3/19/06 7:20 PM, "Andy Lee" <email@hidden> wrote:
> On Mar 19, 2006, at 9:10 PM, Tito Ciuro wrote:
>> NSString *dirPath = [@"~/Library/Preferences/
>> com.apple.Bluetooth.plist" stringByExpandingTildeInPath];
>> NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:
>> dirPath];
>> NSString *desc = [dict description];
>> NSDictionary *newDict = [desc propertyList];
>>
>> It seems that the Bluetooth plist is wrongly formatted (needs a
>> missing semicolon) which crashes NSString's propertyList.
>
> I can reproduce this, and it does look like a bug to me. The problem
> seems to be with dates in the plist file. My Bluetooth.plist
> contains an entry that gets converted to this by the -description
> method:
>
>
> RecentDevices = {
> "00-0a-95-3a-84-5b" = 2006-03-18 23:56:58 -0500;
> "00-0c-55-04-a6-6f" = 2006-03-17 04:01:14 -0500;
> "00-60-57-e6-e1-83" = 2006-03-01 16:46:45 -0500;
> };
>
>
> This is a dictionary whose values are supposed to be dates.
> Unfortunately, the parsing logic in the -propertyList method does not
> recognize them as such. An exception gets thrown by
> CFPropertyListCreateFromXMLData(), and does not get thrown when I
> remove the dates.
>
> Note that it does not help to use -descriptionInStringsFileFormat and
> -propertyListFromStringsFileFormat.
>
> I suspect the solution is to use whatever CoreFoundation function is
> the inverse of CFPropertyListCreateFromXMLData(), because the
> Objective-C APIs for doing what you want are broken right now.
>
> Oh, and file a bug report. :)
>
> --Andy
>
> P.S. Keith Wilson, maybe you didn't run into the problem because
> your Bluetooth.plist file doesn't have a "RecentDevices" entry?
>
>
> _______________________________________________
> 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