Re: Coding question
Re: Coding question
- Subject: Re: Coding question
- From: Drew McCormack <email@hidden>
- Date: Fri, 15 Aug 2003 09:15:18 +0200
On Thursday, August 14, 2003, at 06:04 pm, daniele wrote:
I have a custom class that contains some arrays and dictionaries. Now
i would to archive the class into a file using the NSCoding protocol.
Unfortunatly the docs is not too clear for me and i don't know how to
do it.Must I implement the initWithCoder and encodeWithCOder methods?
If yes, what i must to do inside this methods??
Thanks a lot
Daniele M.
Daniele M.
Yes, implement those two methods:
-(void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:myArray];
[coder encodeObject:myDictionary];
}
-(id)initWithCoder:(NSCoder *)coder {
[super init];
myArray = [[coder decodeObject] retain];
myDictionary = [[coder decodeObject] retain];
return self;
}
That's the basic idea. You must use the same order of encoding/decoding
in each method, unless you decide to use keyed archiving.
Drew
========================================
Dr. Drew McCormack (Kmr. R153)
Afd. Theoretische Chemie
Faculteit Exacte Wetenschappen
Vrije Universiteit Amsterdam
De Boelelaan 1083
1081 HV Amsterdam
The Netherlands
Email email@hidden
Telephone +31 20 44 47623
Mobile +31 6 483 21307
Fax +31 20 44 47629
_______________________________________________
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.