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 {}
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];
}
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:)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With