Re: How To Design A Queue of Messages?
Re: How To Design A Queue of Messages?
- Subject: Re: How To Design A Queue of Messages?
- From: Andreas Mayer <email@hidden>
- Date: Sat, 10 Sep 2005 20:10:49 +0200
Am 10.09.2005 um 19:34 Uhr schrieb Frode:
I would use objc_sendMsg().
Any reason for not simply using performSelector:?
- (id)initWithObjectAndSelector:(id)object selector:sel {
self = [super init];
_receiver = [object class];
if ([object respondsToSelector:sel]) {
// it would be reasonable to check that object implement
selector HERE, // instead of in the loop sendMessages below...
[self dealloc];
return nil;
}
_sel = sel;
return self;
}
This seems wrong. If you want to send a message to 'object' later, it
is no use storing [object class] only; you will have to store 'object'.
I suggest something like this:
NSMutableArray *taskQueue = [[NSMutableArray alloc] init];
- (void)queueTaskWithTarget:(id)target selector:(SEL)selector
{
NSDictionary *task = [NSDictionary
dictionaryWithObjectsAndKeys:target, @"target", NSStringFromSelector
(selector), @"selector", nil];
[taskQueue addObject:task];
}
- (void)performNextTask
{
if ([taskQueue count] > 0) {
NSDictionary *task = [taskQueue objectAtIndex:0];
id target = [task objectForKey:@"target"];
NSString *selectorName = [task objectForKey:@"selector"];
SEL selector = NSSelectorFromString(selectorName);
[target performSelector:selector];
[taskQueue removeObjectAtIndex:0];
}
}
Standard disclaimer: Typed in Mail; not tested.
Andreas
_______________________________________________
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