Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use multiple parameters with the performSelector: method? [duplicate]

Do I use withObject:? And if so, could I just pass, say an NSNumber?

How would it appear in the method's signature?

- (void)methodName:(NSTimer *)timer withObject:(NSNumber *)value {}
like image 770
Doug Smith Avatar asked Dec 08 '22 17:12

Doug Smith


2 Answers

You can use an NSArray object or NSDictionary which encapsulates multiple dataobjects into one! In example:

NSArray * myDataArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:2],@"A String", nil];

[self performSelector:@selector(doStuff:) withObject:myDataArray afterDelay:1.0];

-(void)doStuff:(NSArray *)array{
   NSNumber * myNumber = [array objectAtIndex:0];
   NSNumber * myNumber2 = [array objectAtIndex:1];
   NSString * myString = [array objectAtIndex:2];
}
like image 138
BarryK88 Avatar answered Dec 11 '22 10:12

BarryK88


You can pass at most two parameters directly, using performSelector:withObject:withObject: declared in NSObject protocol.

Using your example, the selector would be @selector(methodName:withObject:).

like image 40
Sulthan Avatar answered Dec 11 '22 11:12

Sulthan