• 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: What part of DO don't I understand?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What part of DO don't I understand?


  • Subject: Re: What part of DO don't I understand?
  • From: Charles Crowley <email@hidden>
  • Date: Tue, 22 Feb 2005 19:39:00 -0700

Byron,

I ran into this same problem. You figured out the first part, that is, to call replacementObjectForPortCoder. After this gets called then Cocoa calls your "encodeWithCoder: (NSCoder *) encoder" method with an encoder. But this encoder is not a keyed archiving encoder but the older kind that encodes by order. You are probably calling "encodeObject:forKey:" in that method and this is the error you are seeing. Change your method to something like this:

- (void) encodeWithCoder: (NSCoder *) encoder {
    if( [encoder allowsKeyedCoding] ) {
	[encoder encodeObject: [self firstName] forKey: firstNameKey];
	[encoder encodeObject: [self lastName] forKey: lastNameKey];
    } else {
	[encoder encodeObject: [self firstName]];
	[encoder encodeObject: [self lastName]];
    }
}

Of course, instead of firstName and lastName you need all the variables in the class that you need to archive. You probably already have all the "encodeObject:forKey:" lines that you need. Just copy them and remove the "forKey:" part.

You need to do a similar thing for your "initWithCoder: (NSCoder *) decoder" method on the receiving side of the DO.

Hope this helps.

--Charlie Crowley


On Feb 22, 2005, at 12:35 PM, Byron Wright wrote:

ok after digging around I found I need to implement the following method in my class to so that bycopy does not return a NSProxy / NSDistributedObject :

- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
	if ([encoder isBycopy]) return self;
	return [super replacementObjectForPortCoder:encoder];
}

I need that but now I get the following exception :

Exception raised during posting of notification. Ignored. exception: *** -encodeObject:forKey: only defined for abstract class. Define -[NSConcretePortCoder encodeObject:forKey:]!

This only happens when my custom class initWithCoder:(NSCoder *) coder gets called.

Any ideas?

- Byron



On Feb 21, 2005, at 6:45 PM, Byron Wright wrote:

So I am attempting to create a server in another thread that is responsible for fetching data on a remote server. I want to collect the data and then send it back to the main thread asynch. I am using Distributed Objects to send the newly created data from the server thread to the main thread. The issue I am having is that the newly created objects (in the server thread) are always sent back to the main thread as a proxy and not copied even though I have the bycopy hint in the method sig. Here is the code I am using as a prototype to understand DO, assume the connects have already been setup (which they have).

//MyServer.h

@class Testobject;

@protocol MyServerMethods

- (oneway void) doSomework;


@end

@protocol MyClientMethods

- (oneway void) workDone : (in bycopy Testobject *) obj;
- (void) setServer: (id) server;

@end

@interface MyServer : NSObject <MyServerMethods>
{
	id clientProxy;
}

- (id) initWithClient: (id) client;
- (oneway void) doSomework;
+ (void)connectWithPorts:(NSArray *)portArray;
@end
/ /--------------------------------------------------------------------- ---


//myClient.h

@interface MyClient : NSObject <MyClientMethods> {

	id<MyServerMethods> myServer ;
	NSConnection* kitConnection;

}
- (IBAction) doWork: (id) sender;
- (void) setServer: (id) server;
- (oneway void) workDone : (in bycopy Testobject *) obj;
- (void) createServer;


@end
/ /--------------------------------------------------------------------- ---


so my server does some work then sends a new object to the main thread (MyClient)

so my client called doSomework from the main thread.

- (oneway void) doSomework
{
	int total = 1000;
	int it = 0;
	for(it ; it < total; ++it)
	{
		NSLog(@"doSomework %i",it);
	}
	Testobject * obj = [[Testobject alloc] init];
	//done send back to main thread
	[clientProxy workDone:obj ];
	//[obj release];
}

MyClient then accepts the new data :

- (oneway void) workDone : (in bycopy Testobject *) obj;
{
	NSLog(@"myClient:workDone");
	if([obj isProxy])
	{
		NSLog(@"I am baffled");
	}
	NSLog(@"obj = %@",[obj description]);
}

problem is obj isProxy is always true. Also, something else I found out the hard way, NSLog(@"obj = %@",obj) always crashes if it's an NSProxy, I am guessing because NSProxy does not know how to dispatch this call?

here is the simple data object I am using for testing:

@interface Testobject : NSObject  <NSCoding>{
	NSString * val;
}
- (NSString *)val;
- (void)setVal:(NSString *)aVal;

@end


Any help is always appreciated.

Cheers,
Byron


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden




_______________________________________________ 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


_______________________________________________ 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
  • Follow-Ups:
    • Re: What part of DO don't I understand?
      • From: Byron Wright <email@hidden>
References: 
 >What part of DO don't I understand? (From: Byron Wright <email@hidden>)
 >Re: What part of DO don't I understand? (From: Byron Wright <email@hidden>)

  • Prev by Date: Re: Not-documents, but similar
  • Next by Date: Re: controller keys
  • Previous by thread: Re: What part of DO don't I understand?
  • Next by thread: Re: What part of DO don't I understand?
  • Index(es):
    • Date
    • Thread