• 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
Re: Understanding user defaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Understanding user defaults


  • Subject: Re: Understanding user defaults
  • From: Marcel Weiher <email@hidden>
  • Date: Tue, 19 Mar 2013 11:02:02 +0100

On Mar 19, 2013, at 1:19 , Jens Alfke <email@hidden> wrote:

>
> On Mar 18, 2013, at 5:14 PM, Rick Mann <email@hidden> 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@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: Understanding user defaults
      • From: James Montgomerie <email@hidden>
References: 
 >Understanding user defaults (From: Rick Mann <email@hidden>)
 >Re: Understanding user defaults (From: Graham Cox <email@hidden>)
 >Re: Understanding user defaults (From: Rick Mann <email@hidden>)
 >Re: Understanding user defaults (From: Jens Alfke <email@hidden>)
 >Re: Understanding user defaults (From: Rick Mann <email@hidden>)
 >Re: Understanding user defaults (From: Jens Alfke <email@hidden>)

  • Prev by Date: Is there a way to access the native iOS Notes app to create new notes?
  • Next by Date: Re: Understanding user defaults
  • Previous by thread: Re: Understanding user defaults
  • Next by thread: Re: Understanding user defaults
  • Index(es):
    • Date
    • Thread