• 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: Help with simple EncodeObject & DecodeObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with simple EncodeObject & DecodeObject


  • Subject: Re: Help with simple EncodeObject & DecodeObject
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 27 May 2002 23:13:50 -0700

On Monday, May 27, 2002, at 10:44 PM, Carlos Weber wrote:

If you have access to Aaron Hillegass' book, Cocoa Programming for Mac OS X, he devotes a chapter (Chapter 6: Archiving) to this very topic. Briefly, NSArchiver's class method, + (NSData *)archivedDataWithRootObject: (id)rootObject is what you want, as long as your root object adheres to the <NSCoding> protocol.

This is fine if you have a root object -- Steve pointed out that he does not have a "root object", rather a collection of individual variables.

One possible solution is to put these objects in to a collection object, an array or dictionary, and archive that (using archivedDataWithRootObject).

Alternatively, to keep the current approach, the suspect line in the original code is:

NSUnarchiver *a_unarchiver =
[NSUnarchiver unarchiveObjectWithData:data];


From the documentation, the definition of unarchiveObjectWithData is as follows:

"Decodes and returns the object archived in data. This method invokes initForReadingWithData: and decodeObject to create a temporary NSUnarchiver that decodes the object. If the archived object is the root of a graph of objects, the entire graph is unarchived."

The code does not return a new NSUnarchiver object, as I suspect Steve anticipates; instead it is extracting the first object from the archive. Replacing the line with

NSUnarchiver *a_unarchiver = [[[NSUnarchiver alloc]
initForReadingWithData:data] autorelease];

*may* solve the problem...

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Help with simple EncodeObject & DecodeObject (From: Carlos Weber <email@hidden>)

  • Prev by Date: Re: Help with simple EncodeObject & DecodeObject
  • Next by Date: Re: Help with simple EncodeObject & DecodeObject
  • Previous by thread: Re: Help with simple EncodeObject & DecodeObject
  • Next by thread: Re: Help with simple EncodeObject & DecodeObject
  • Index(es):
    • Date
    • Thread