• 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: Property List Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Property List Question


  • Subject: Re: Property List Question
  • From: Stefan Arentz <email@hidden>
  • Date: Thu, 17 May 2001 10:45:07 +0200

On Wednesday, May 16, 2001, at 04:30 AM, Karl Goiser wrote:

Hello,

I have a question about property lists:

I have data which is a list of information about objects that I want to store in a property list - it is basically like a list of information about people.

So I want to represent it as an array of arrays of strings. This way, I can easily read and store the data with methods like "arrayWithContentsOfFile:" and "writeToFile:atomically:".

The problem is is that I want to represent the 'people' as objects (for the obvious OO benefits). However, if I do, I will lose the ability to use "arrayWithContentsOfFile:" and "writeToFile:atomically:" because the array will no longer contain only property list objects.

Is there a protocol or something which I can make the 'people' objects conform to which will make the saving and loading work?

There is a great API for that in Foundation. Just implement the NSCoding protocol and you're all set. Specifically, implement encodeWithCoder: and initWithCoder: and your objects can be serialized to a file. You can simply do a

[NSArchiver archiveRootObject: yourArray toFile: @"/Path/To/File"];

and voila, serialized data!

The beauty is that NSArray (and most other collection classes in Foundation) implements NSCoding, so it just works.

You want to read about NSArchiver, NSUnarchiver and NSCoding.

Stefan


  • Follow-Ups:
    • Re: Property List Question
      • From: mmalcolm crawford <email@hidden>
References: 
 >Property List Question (From: Karl Goiser <email@hidden>)

  • Prev by Date: Re: Property List Question
  • Next by Date: Re: mp3 streaming?
  • Previous by thread: Re: Property List Question
  • Next by thread: Re: Property List Question
  • Index(es):
    • Date
    • Thread