• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSKeyedArchiever and XML Format
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSKeyedArchiever and XML Format


  • Subject: NSKeyedArchiever and XML Format
  • From: Patrick Mau <email@hidden>
  • Date: Thu, 11 Dec 2008 10:01:48 +0100

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"];
[a finishEncoding];
[data writeToFile:@"/Users/mau/Desktop/encodeRoot.plist" atomically:YES];
[a release];


The property list editor shows the root object key as "Root", but in fact the key is saved as 'root'.

I was unable to unarchieve my objects using 'unarchiveObjectWithFile' until I finally created a
hex-dump and figured out that the only difference between the files was 'root' versus 'Root':


Did I miss a convenience method to create a compatible XML file?

I did not find the '[a encodeObject:p forKey:@"root"];' in the documentation,
it is based on my investigation.


Regards,
Patrick

PS: Somehow copy & paste from Xcode created this colorful message. I hope it is readable.


_______________________________________________

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


  • Follow-Ups:
    • Re: NSKeyedArchiever and XML Format
      • From: Nathan Vander Wilt <email@hidden>
    • Re: NSKeyedArchiever and XML Format
      • From: Martin Wierschin <email@hidden>
  • Prev by Date: Re: Wizard development on Mac
  • Next by Date: Re: NSOutlineView problem with Text cells.
  • Previous by thread: Re: AddressBook Framework, adding multiple records
  • Next by thread: Re: NSKeyedArchiever and XML Format
  • Index(es):
    • Date
    • Thread