Re: NSString propertyList crash
Re: NSString propertyList crash
- Subject: Re: NSString propertyList crash
- From: Andy Lee <email@hidden>
- Date: Sun, 19 Mar 2006 23:31:18 -0500
On Mar 19, 2006, at 11:01 PM, Greg Herlihy wrote:
There is no bug here: an NSDictionary object cannot be initialized
with a
binary plist file.
Are you sure? It certainly worked in this case, or so my debugger
tells me, but maybe the file I gave it just happened to work. Also,
I'm running Tiger 10.4.5 -- does your statement apply to earlier OS
versions?
In any case, your code below certainly avoids any chance of
encountering the problem.
I would still claim there is a bug, because according to the docs, -
[NSDictionary description] and -[NSString propertyList] should
convert between string and dictionary representations, and I can
create a trivial case where that is not true:
NSDictionary *dict =
[NSDictionary dictionaryWithObjectsAndKeys:
[NSDate date], @"today",
nil];
NSString *desc = [dict description];
NSDictionary *newDict = [desc propertyList]; // throws exception
--Andy
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
_______________________________________________
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