Re: NSKeyedArchiver -> NSDictionary?
Re: NSKeyedArchiver -> NSDictionary?
- Subject: Re: NSKeyedArchiver -> NSDictionary?
- From: Scott Anguish <email@hidden>
- Date: Wed, 24 Mar 2004 03:57:23 -0500
the only way to get the data out in the form of a dictionary, is to
ensure that the data you archive is an NSDictionary containing only
values that can be stored in a plist.. so you don't really get any win
doing it this way.
I'd suggest instead that you simply store your initial defaults as a
plist in your application wrapper. You'll need to ensure that
everything is able to be coded to a plist anyways for user defaults.
if you have a situation where you want to specify something that isn't
easily encoded into defaults as an initial default value you could
write a small tool that spits out that value only as an NSData encoded
value - and then paste that hexdump into the plist value.. you'll need
to decode it when you ask for the object value from NSUserDefaults
anyways.
On Mar 24, 2004, at 3:07 AM, David Faden wrote:
Hi,
Is there an elegant way to convert the data encoded by an
NSKeyedArchiver into a corresponding NSDictionary suitable for use
with NSUserDefaults? I was hoping to be able to use an NSKeyedArchiver
in building the default preferences for an app. The methods provided
in Foundation seem tantalizingly close to providing what I want. The
following code goes part of the way towards what seems to me an
inelegant solution (basically "manually" decomposing the property
list).
NSMutableData* data = [NSMutableData data];
NSKeyedArchiver* archiver = [[[NSKeyedArchiver alloc]
initForWritingWithMutableData:data] autorelease];
NSString* xmlString = nil;
id propertyListDictionary;
[archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
//archive some stuff ...
[archiver finishEncoding];
xmlString = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
propertyListDictionary = [xmlString propertyList];
//...
Is there a nice way to go from an NSKeyedArchiver to an NSDictionary
in a form suitable for use with NSUserDefaults?
Please CC replies to me as well as sending them to the list. (I have a
backlog of around 6400 cocoa-dev messages to sort through currently
:-)).
Thanks.
David
AIM: pitulx
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.