I have been trying to get the NSKeyedArchiver to write out my data in a human readable form (i.e. not as a binary file) I understand that I can use …
setOutputFormat: NSPropertyListXMLFormat_v1_0
But … I just can’t seem to get the syntax right, can anyone point me in the right direction?
NSData *artistData;
NSLog(@"(*) - Save All");
artistData = [NSKeyedArchiver archivedDataWithRootObject:artistCollection ];
[artistData writeToFile:@"/Users/fgx/Desktop/stuff" atomically:YES];
EDIT
I added setOutputFormat (see below) but I get a warning at compile, what am I missing?
warning: NSData may not respond to 'setOutputFormat:'
Here is the code I used.
NSLog(@"(*) - Save All");
artistData = [NSKeyedArchiver archivedDataWithRootObject:artistCollection ];
[artistData setOutputFormat: NSPropertyListXMLFormat_v1_0];
[artistData writeToFile:@"/Users/fgx/Desktop/stuff" atomically:YES];
gary
This is what you have to do:
Note that you must use
[archiver encodeObject:artistCollection forKey:@"root"]instead of[archiver encodeRootObject:artistCollection];as suggested by Sean. This is because NSKeyedArchiver does not override NSCoder encodeRootObject: method. I consider this a bug and will report it to Apple.Now, the real question is why do you want to write XML instead of the default binary format? If it’s for debugging purpose, I suggest you to use TextWrangler which will allow you to transparently edit binary plist files as if they were XML.