iphonecocoa-touchnsoperationnsoperationqueuensinvocationoperation

Multiples arguments to NSOperation?


I'm using NSOperationQueue in my app and i want to set multiples arguments to my operation how can i do that?

   NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
   NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(methodCall) object:nil];
  [queue addOperation:operation];
  [operation release];

Solution

  • You will have to create an array or dictionary with the data you need.

    Ex:

    NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
    NSDictionary *argumentDictionary = [NSDictionary dictionaryWithObjectsAndKeys:object1, @"Object1Key", object2, @"Object2Key", nil];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(methodCall:) object:argumentDictionary];
    [queue addOperation:operation];
    [operation release];
    

    and in - (void)methodCall:(NSDictionary *)argumentDictionary you can use the objects and values stored in that dictionary.