• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Distributed Objects, copying thereof
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Distributed Objects, copying thereof


  • Subject: Re: Distributed Objects, copying thereof
  • From: Philip Mötteli <email@hidden>
  • Date: Thu, 8 Jun 2006 21:16:10 +0200


Am 08.06.2006 um 20:16 schrieb Jim Thomason:

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;
}
}

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?

It did strike me too.
It gets even worse: Arrays are always copied. This is very annoying when using HOMs.
One can simply say, that the ObjC keyword "bycopy" doesn't serve for anything at all.
So what I did, was that I exchanged NSObject's - replacementObjectForPortCoder: for this:


- PMreplacementObjectForPortCoder:(NSPortCoder *)aCoder
{
return [aCoder isBycopy] ? self : [self origReplacementObjectForPortCoder:aCoder];
}


This way, I'm sure, that an object will be copied, when I want it to be. I can decide that in my code and don't have to implement that on a class basis all over the place.
In my eyes, this is a bug.



Re Phil

_______________________________________________
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


References: 
 >Distributed Objects, copying thereof (From: "Jim Thomason" <email@hidden>)
 >Re: Distributed Objects, copying thereof (From: John Pannell <email@hidden>)
 >Re: Distributed Objects, copying thereof (From: "Jim Thomason" <email@hidden>)

  • Prev by Date: Re: NSBorderlessWindowMask causes grey disabled controls?
  • Next by Date: NSKeyedUnarchiver Exception, No Idea
  • Previous by thread: Re: Distributed Objects, copying thereof
  • Next by thread: Re: Distributed Objects, copying thereof
  • Index(es):
    • Date
    • Thread