Does Objective C have a function like Smalltalk’s Block valueWithArguments?
I’m looking for a function with a signature like:
apply(^(), NSArray* args)
Alternatively, is there a way to call a selector over a list of arguments?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
With blocks you probably have to do some
va_argsmagic. Calling a selector with variable arguments can be done but you probably want some helpers to make it a bit less painful.NSObject+performSelectorWithArgsArray.h
NSObject+performSelectorWithArgsArray.m
And then use it like this:
If you choose to do something like this I recommend that you really read up on how
NSInvocationworks as it can bite quite hard. Not sure if it is possible to do this without requiring that all arguments and return value are objects.