• 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: Archiving/unarchiving root objects using instance methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Archiving/unarchiving root objects using instance methods


  • Subject: Re: Archiving/unarchiving root objects using instance methods
  • From: "A.M." <email@hidden>
  • Date: Mon, 9 Mar 2009 16:20:11 -0400


On Mar 9, 2009, at 3:59 PM, Paul Kim wrote:

I have been using NSKeyedArchiver's +archivedDataWithRootObject: method to create archives. Now, I want to create and read the same archives but using a instances of NSKeyedArchiver and NSKeyedUnarchiver instead of the class methods (so I can do things like set a delegate, for instance). The problem is is that to produce the same archive using instance methods as opposed to the class convenience method, I have to encode the object with the undocumented "root" key. I understand not wanting to expose that in the API but I can't seem to find the methods to produce the same output using an instance.

I've tried -encodeRootObject (defined in NSCoder) thinking NSKeyedArchiver's version might do the right thing by encoding with an implicit "root" key but not so. The resulting archive cannot be read by NSKeyedUnarchiver's +unarchiveObjectWithData.

If I am missing something here, then let me know. And re-defining the format is not acceptable as there are many files out there in the field. It seems a bit silly if it is indeed the case that the "convenience" methods provide no supported way to do it "inconveniently." And yes, for practical reasons, using the "root" key will work because of backwards compatibility but it would be nice if there were an official way to do this (or some semi-official word that using the "root" key is ok).

I have successfully subclassed NSKeyed[Un]archiver for a similar purpose. Here are the methods I used:


__Archiver__
initForWritingWithMutableData:
encodeRootObject:
finishEncoding
return (mutable data from above)

__Unarchiver__
initForReadingWithData:
decodeObject

Cheers,
M

_______________________________________________

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: Archiving/unarchiving root objects using instance methods
      • From: Paul Kim <email@hidden>
References: 
 >Archiving/unarchiving root objects using instance methods (From: Paul Kim <email@hidden>)

  • Prev by Date: Re: MVC, storing VIEW-specific information and core data
  • Next by Date: Re: Archiving/unarchiving root objects using instance methods
  • Previous by thread: Archiving/unarchiving root objects using instance methods
  • Next by thread: Re: Archiving/unarchiving root objects using instance methods
  • Index(es):
    • Date
    • Thread