Soheil Novinfard Soheil Novinfard - 18 days ago 6
Objective-C Question

OR statement in the arguments of method

I have a method like this:

-(void)exampleSend:(NSString *)gateway byParams:(NSDictionary *)params{
...
}


Now I want to change
params
, which is an input argument, to something that support both
NSDictionary
and
NSArray
. How can I do this in objective-c ?

Answer

Change the type to id instead of NSDictionary and make sure you should check inside your method if its NSDictionary or NSArray before performing any class specific actions on it, otherwise it will cause a crash.

-(void)exampleSend:(NSString *)gateway byParams:(id)params{

    if([params isKindOfClass:[NSDictionary class]]){

    }else{

    }
    ...
}
Comments