Another aproach you can use is to pass an NSArray
or an NSMutableArray
as parameter to your method.
An Example:
NSString *firstItem = @"first Item";
NSNumber *secondItem = [[NSNumber numberWithBool:YES];
YourCustomObject *thirdItem= [[YourCustomObject alloc] init];
//your array to pass
NSArray *arrayToPass = [[NSArray arrayWithObjects:firstItem, secondItem, thirdItem, nil];
//call you method after delay and pass all the objects:
[self oerformSelector:@selector(doStuffWithMultipleParams:) withObject:arrayToPass afterDelay:3.0f];
The method could be used like this:
- (void)doStuffWithMultipleParams:(NSArray *)passedArray{
String *s;
BOOL b;
YourCustomObject *obj;
if ([[passedArray objectAtIndex:0] isKindOfClass:[NSString class]]){
s = [passedArray objectAtIndex:0];
}
if ([[passedArray objectAtIndex:1] isKindOfClass:[NSNumber class]]){
b = [[passedArray objectAtIndex:1] boolValue];
}
if ([[passedArray objectAtIndex:1] isKindOfClass:[YourCustomObject class]]){
obj = [passedArray objectAtIndex:2];
}
if (s || b || obj){
//now do stuff with these objects
}
}