Re: DO doesn't like my objects
Re: DO doesn't like my objects
- Subject: Re: DO doesn't like my objects
- From: Lindsey Spratt <email@hidden>
- Date: Mon, 25 Nov 2002 15:04:00 -0600
On Monday, November 25, 2002, at 01:31 PM,
email@hidden 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 unarchiveObjectWith
Data:[_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@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.