Re: NSKeyedArchiever and XML Format
Re: NSKeyedArchiever and XML Format
- Subject: Re: NSKeyedArchiever and XML Format
- From: Nathan Vander Wilt <email@hidden>
- Date: Thu, 11 Dec 2008 17:16:41 -0800
On Dec 11, 2008, at 1:01 AM, Patrick Mau wrote:
Good morning
For the last day I have pulled my hair over NSKeyedArchiever and
friends to load and save small data objects.
I mainly use this feature for debugging, so the output format is set
to XML.
Normally, one would write an object 'p' in binary format, using:
[NSKeyedArchiver archiveRootObject:p toFile:@"/Users/mau/Desktop/
archiveRoot.plist"];
Reading the object again would be done using:
p = [NSKeyedUnarchiver unarchiveObjectWithFile:@"/Users/mau/
Desktop/archiveRoot.plist"];
To set the output format one cannot use the convenience methods
above, but the following:
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *a = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:data];
[a setOutputFormat:NSPropertyListXMLFormat_v1_0];
[a encodeObject:p forKey:@"root"];
Does using:
[a encodeRootObject:p];
instead of the line above make it work as expected?
[a finishEncoding];
[data writeToFile:@"/Users/mau/Desktop/encodeRoot.plist"
atomically:YES];
[a release];
hope this helps,
-natevw
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden