So basically I’m implementing the typical way to handle JavaScript calls in objc using window.location=”myobj:mymethod:myarg:myotherarg”, however, I’m wondering if there is a way to apply an array of arguments to a method, similar to how you can in JavaScript.
Typically I’ve been doing
-(void) mymethod:(NSArray*) arr{
//method knows how many arguments it takes and what they mean at each index
}
I’d prefer to do:
-(void) mymethod:(NSString*) myarg myOtherArg: (NSString*) myotherarg{
//do stuff
}
and have a method like this:
+(void) callMethod:(NSString*)selectorName withArgs: (NSArray*)args onObject:(id) obj{
//implementation
}
[JEHelpers callMethod:selector withArgs:someArrayOfArgs onObject:myapp]
is this possible?
If you know that no method will take more than two arguments, you could use
performSelector:withObject:withObject:to do these calls. If the method takes less than two arguments, the unusedwithObject:fields will be ignored.If there could be more than two arguments, you will have to use
NSInvocation. This class lets you construct a message by passing the various arguments and defining the selector and object, then send the message and get the result.