How to use multiple parameters using the performSelector method :?

Do I use withObject :? And if so, can I just go through, say, NSNumber?

How will it appear in the method signature?

- (void)methodName:(NSTimer *)timer withObject:(NSNumber *)value {} 
+4
source share
3 answers

You can use an NSArray or NSDictionary, which encapsulates multiple data objects into one! In the 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]; } 
+10
source

You can pass no more than two parameters directly using performSelector:withObject:withObject: declared in the NSObject protocol.

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

+4
source

You can not. However, you can pass an NSDictionary to / from which you can package and extract multiple objects.

Also see the NSInvocation class.

0
source

Source: https://habr.com/ru/post/1469377/


All Articles