The best way to archive dependancies
The best way to archive dependancies
- Subject: The best way to archive dependancies
- From: Francisco Tolmasky <email@hidden>
- Date: Sun, 11 May 2003 15:17:33 -0700
Ok, I have two classes something like this:
@interface A: NSObject
{
NSMutableArray *Bs;
}
@end
@interface B: NSObject
{
A * parentA;
}
@end
For one reason or another, I need all the B's stored in A to know whom
their parent A is. Now, this is all good and dandy, until I need to
archive. I know that NSArchiver archives references when it encounters
the same object more than once, but I don't know if this applies here:
@implementation A
- (id)initWithCoder:(NSCoder *)aCoder
{
self= [super init];
if(self) Bs= [[aCoder decodeObject] retain];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[Bs encodeWithCoder: aCoder];
}
@end
@implementation B
- (id)initWithCoder:(NSCoder *)
{
self= [super init];
if(self) parentA= [aCoder decodeObject];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[parent encodeWithCoder: aCoder];
}
@end
Is this correct? Will this work? Or will it be circular and crash?
Is there a different way of doing this, making some sort of
initWithCoder:parentA: message, subclassing nscoder to have a
decodeObjectWithDependancy: ?
Thank you in advance.
Francisco Tolmasky
email@hidden
http://users.adelphia.net/~ftolmasky
_______________________________________________
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.