In an Xcode project I have a C file with functions, it compiles and works OK
I want to wrap my C code in struct(s), how will I be able to call them in Objective-C?
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.
Declare function pointers, add them to your structure and then call them, it’s just C.
Example:
Output:
If you want to have a struct with functions where functions operate on the structure you have to pass the pointer to that function by default (similar to what c++ does):
Define:
As you can see these functions could be standalone, you would still pass the ClassABC in:
Initialization helper func:
Usage:
Output:
Enjoy