Skip navigation.
 
mlRe: Distributed Objects, copying thereof
FROM : Jim Thomason
DATE : Thu Jun 08 20:16:25 2006

> 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.....

Related mailsAuthorDate
mlDistributed Objects, copying thereof Jim Thomason Jun 8, 18:23
mlRe: Distributed Objects, copying thereof John Pannell Jun 8, 18:49
mlRe: Distributed Objects, copying thereof Jim Thomason Jun 8, 20:16
mlRe: Distributed Objects, copying thereof Philip Mötteli Jun 8, 21:16
mlRe: Distributed Objects, copying thereof Jim Thomason Jun 9, 02:34
mlRe: Distributed Objects, copying thereof John Pannell Jun 9, 03:09
mlRe: Distributed Objects, copying thereof Chris Kane Jun 9, 20:21