Skip navigation.
 
mlRe: DO doesn't like my objects
FROM : Lindsey Spratt
DATE : Mon Nov 25 22:04:00 2002

On Monday, November 25, 2002, at 01:31  PM,
<email_removed> wrote:

> If I return NSStrings or NSValues, it works absolutely fine.  If I
> return my own home-brewed objects, no dice.  The returned object is
> nil, and trying to retain it produces an exception of NSCFArray
> addObject:] attempt to insert nil, even though I am not putting it in
> an array.  The objects that I want to return conform to NSCopying and
> NSCoding.  I originally thought that was the problem, but it didn't
> help at all.


I have been having DO/NSCoding problems something like this myself. I
have app-specific objects that inherit directly from NSObject and
conform to the NSCoding protocol, but the Distributed Object mechanism
doesn't seem to notice. My approach has been to explicitly invoke
NSArchive/NSUnarchive. For instance, to have a method return "stuff"
(some object conforming to NSCoding) from thread 1 to the caller on
thread 2:

In object on thread 1:
- (NSData*) methodReturningDataToOtherThread
{
   return [NSArchiver archivedDataWithRootObject:_thread1Stuff];
}

In object on thread 2:
-(Stuff*)getStuffFromOtherThread
{
   return  [NSUnarchiver unarchiveObjectWithData:[_proxy
methodReturningDataToOtherThread]];
}

The variable _proxy holds a ref to the DO proxy object that connects to
thread 1.

Stuff is:
@interface Stuff : NSObject <NSCoding> {
   int _x;
   int _y;
   
   OtherStuff* _otherStuff;
}
- (void)encodeWithCoder:(NSCoder *)encoder;
- (id)initWithCoder:(NSCoder *)coder;
@end

@interface OtherStuff : NSObject <NSCoding> {
   int _z;
}
- (void)encodeWithCoder:(NSCoder *)encoder;
- (id)initWithCoder:(NSCoder *)coder;
@end


This approach works fine, but stripping out the NSArchiver/NSUnarchiver
material does not.

Seems odd to me, but at least it's working.

Lindsey Spratt
http://homepage.mac.com/lspratt
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlDO doesn't like my objects Matt Massicotte Nov 25, 16:14
mlRe: DO doesn't like my objects Lindsey Spratt Nov 25, 22:04
mlRe: DO doesn't like my objects Matt Massicotte Nov 26, 02:58