Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSKeyedArchiver -> NSDictionary?



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.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.