Re: bycopy in and NSDistantObject in return
Re: bycopy in and NSDistantObject in return
- Subject: Re: bycopy in and NSDistantObject in return
- From: "Adam R. Maxwell" <email@hidden>
- Date: Wed, 21 Feb 2007 13:49:55 -0800
On Wednesday, February 21, 2007, at 10:26AM, "Claudio Procida" <email@hidden> wrote:
>I'm using DO to communicate with a worker thread. At a certain point,
>the worker thread returns an array to the owner with the following
>method:
>
>@protocol SGWorkerOwner
>//...
>- (oneway void)setTree:(bycopy in id)tree;
>//...
>@end
>
[...]
>What is not clear to me is if why, if I ask for a copy of the tree
>object, the receiver gets a NSDistantObject:
>
>- (oneway void)setTree:(bycopy in id)tree
>{
> NSLog(@"%@ (%@)", [tree objectAtIndex:0], [[tree objectAtIndex:0]
>class]);
>
>2007-02-21 19:11:43.361 Singular[16991] <SGDuplicateTreeNode:
>0x4859c60> (<NSDistantObject: 0xa295aa18>)
>
>Maybe I didn't get it ... can someone please explain me what am I
>doing wrong?
You need to implement -SGDuplicateTreeNode replacmentObjectForPortCoder:] if you haven't already. Here's the implementation I use (see the docs for details):
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
return [encoder isByref] ? (id)[NSDistantObject proxyWithLocal:self connection:[encoder connection]] : self;
}
Since NSPortCoder doesn't support keyed archiving, you'll need to implement the old-style archiving as well. My workaround is something like this (with corresponding decode method):
- (void)encodeWithCoder:(NSCoder *)coder{
if([coder allowsKeyedCoding]){
[coder encodeObject:foo forKey:@"bar"];
} else {
[coder encodeDataObject:[NSKeyedArchiver archivedDataWithRootObject:self]];
}
}
Hope this helps.
Adam
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden