Search code examples
iosobjective-cdictionaryselectornsthread

Send NSDictionary as an parameter in @selector


How can I send my NSDictionary on my selector, as a parameter, and how I can read it?

NSDictionary * dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"idOferta",@"test", nil];                
NSThread * viewsThread = [[NSThread alloc] initWithTarget:self selector:@selector(updateViewStatistic:) object:dict];
[viewsThread start];

- (void)updateViewStatistic:(NSThread *)mt {
      NSLog(@"dictionary %@",dict); 
}

Solution

  • Change your updateViewStatistic: method to something like this:

    - (void)updateViewStatistic:(NSDictionary *)dictionary
    {
        NSLog(@"Dictionary: %@", dictionary);
    }