Re: Still problems with storing preferences
Re: Still problems with storing preferences
- Subject: Re: Still problems with storing preferences
- From: Nick Zitzmann <email@hidden>
- Date: Thu, 9 Oct 2003 18:20:29 -0700
On Thursday, October 9, 2003, at 03:46 PM, Eivind Andersen wrote:
Is there anyone who can explain to me how I can store a
NSMutableArray, containing objects from a self-made class? If so, I
would be MOST thankful!
The only objects that can be stored into NSUserDefaults (or property
list files in general) are arrays, dictionaries, strings, numbers
(including booleans), dates, and data. No other objects can be
_directly_ stored in NSUserDefaults...
To store other kinds of data, you must use NSArchiver to turn the class
into data, and NSUnarchiver to turn the data back into a class. Before
you can do this, you must make this class conform to the NSCoding
protocol, which you can read about here:
<
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Protocols/NSCoding.html>
All you need to do in the -encodeWithCoder: and -initWithCoder: classes
is, given an NSCoder object, you just use it to decode (in
-initWithCoder:) and encode (in -encodeWithCoder:) the objects in the
class. If you and your users are using 10.2.x or later, you can use the
"key" methods in NSCoder to make this easier...
This may all sound overwhelming, but I think you'll miss NSCoding if
you ever have to save multiple instances of one or more classes to disk
in C++...
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://seiryu.home.comcast.net/
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone." - Bjarne Stroustrup
_______________________________________________
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.