On Mar 19, 2013, at 1:19 , Jens Alfke <[email protected]> wrote: > > On Mar 18, 2013, at 5:14 PM, Rick Mann <[email protected]> wrote: > >> NSArchiver calls look like -setValue:forKey:, so it seems reasonable that >> the protocol could be usurped to write out fairly clean user defaults plists. > > There’s a lot of other gunk the archiver needs to store so it can handle > pointer cycles and remember what classes to re-instantiate. As I said, look > at some XML generated by NSArchiver sometime.
Yes, but those can be handled in a cleaner way than what NSKeyedArchiver does. As an example, check out the "MPWXmlArchiver" in Objective-XML ( https://github.com/mpw/Objective-XML ). It reflects the object-graph as directly in XML as possible, using the "id"/"idref" mechanism specified in the XML spec to handle repeated occurrences of the same object. I remember people using it for debugging by dumping complex object graphs as XML. It currently doesn't restrict the objects in the graph on reading, but that would be a fairly simple exercise. Example 1, archiving a simple object representing an integer: (MPWXmlArchiver archivedDataWithRootObject:(MPWInteger integer:2)) stringValue <?xml version="1.0" encoding="UTF-8"?> <MPWInteger id='0'> <intValue valuetype='i'>2</intValue> </MPWInteger> Example 2, archiving an array containing the same integer object twice: theAnswer := MPWInteger integer:42. a := #(), theAnswer, theAnswer (MPWXmlArchiver archivedDataWithRootObject:a) stringValue <?xml version="1.0" encoding="UTF-8"?> <NSMutableArray id='0'> <count valuetype='i'>2</count> <arrayelement valuetype='@'> <MPWInteger id='1'> <intValue valuetype='i'>42</intValue> </MPWInteger> </arrayelement> <arrayelement idref='1'/> </NSMutableArray> It will use keys provided if possible, and punt if it can't find anything. (MPWXmlArchiver archivedDataWithRootObject:32.0) stringValue <?xml version="1.0" encoding="UTF-8"?> <NSNumber id='0'> <unnamed_1 valuetype='*'>f</unnamed_1> <unnamed_2 valuetype='f'>32</unnamed_2> </NSNumber> > _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
