• 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: How To Design A Queue of Messages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: How To Design A Queue of Messages?
      • From: Frode <email@hidden>
References: 
 >How To Design A Queue of Messages? (From: Jerry Krinock <email@hidden>)
 >Re: How To Design A Queue of Messages? (From: Andreas Mayer <email@hidden>)
 >Re: How To Design A Queue of Messages? (From: Frode <email@hidden>)

  • Prev by Date: Re: How To Design A Queue of Messages?
  • Next by Date: IDE
  • Previous by thread: Re: How To Design A Queue of Messages?
  • Next by thread: Re: How To Design A Queue of Messages?
  • Index(es):
    • Date
    • Thread