Re: Distributed Objects, copying thereof
Re: Distributed Objects, copying thereof
- Subject: Re: Distributed Objects, copying thereof
- From: "Jim Thomason" <email@hidden>
- Date: Thu, 8 Jun 2006 13:16:25 -0500
To send an object "across the wire" in DO, your object needs to implement
the NSCoding protocol. As an additional note (that I didn't encounter in
Apple docs), the object that does the coding in DO (NSPortCoder, I believe)
does not seem to support keyed coding, so be sure your encodeWithCoder: and
initWithCoder: methods are old school, and not keyed.
Your object also needs to also implement the following method, in order to
tell the NSPortCoder to package up and send your actual object contents, not
just a reference to the object:
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
if ([encoder isByref]){
return [NSDistantObject proxyWithLocal:self connection:[encoder
connection]];
} else {
return self;
}
}
Thank you.
While this response is indeed correct and does seem to do what I need
it to do (and, I admit, more simply that my whole "encode to
data/decode myself" nonsense), I've gotta say that it is grade-A
bullplop.
Recall - I'm using NSBezierPaths and NSImages. Those are all that I'm
sending across the wire. Built in apple classes. Merely adding in the
bycopy keyword isn't enough to make my code work, no, I actually do
need to implement replacementObjectForPortCoder:
But, these are apple's classes, not my own. So I'm adding on
categories to NSImage and NSBezierPath to do nothing more than
implement this boilerplate method. And that works just fine.
So why oh why didn't Apple just implement that little boilerplate
version as NSObject's default? As I understand the docs now,
NSObject's always returns a distant proxy and apparently completely
ignores NSPortCoder's byref/bycopy/etc flags, which in turn requires
me to tack on a category to implement a more useful version.
Am I way off base, or does this strike anyone else as being really silly?
-Jim.....
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden