I’d like to pass a C function as an argument to an Objective-C method, to then act as a callback. The function has type int (*callback)(void *arg1, int arg2, char **arg3, char **arg4).
I keep getting the syntax wrong. How do I do this?
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.
As a slightly more complete alternative to KKK4SO’s example:
Basically, it’s the same as anything else, except that without the typedef, you don’t specify the name of the callback when specifying the type of the parameter (the
callbackparameter in eithercallFunction:method). So that detail might have been tripping you up, but it’s simple enough.