0

I'm using the code below to pass multiple values to NSOperation.

I have defined an NSDictionary but I can't access on it (it returns always null) within the method called.

Below is my code to invoke the method

NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
@"key1", @"value1",
@"key2", @"value2",
nil];

NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(method:) object:params];
[queue addOperation:operation];

Here is my method definition

- (void) method: (NSDictionary *) params {
     NSLog(@"value1: %@", [[params objectForKey:@"key1"] stringValue]);
}

The method called method is called but the NSLog prints always null when I actually aspect to see value1 as per my dictionary definition.

Am I missing something?

Tnx

Mario Catena
  • 575
  • 1
  • 8
  • 20

1 Answers1

2

As the method name initWithObjectsAndKeys indicates, in your case, @"key1" is the value/object and @"value1" is the key. Also, there is no stringValue method in the NSString object. So, try:

NSLog(@"value1: %@", [params objectForKey:@"value1"]);
user1885297
  • 586
  • 2
  • 6