I have Objective-C class in my iOS project that implements Objective-C and C code in the same class. I changed the extension to .mm and this part goes well. Now I want to set a C method that will call the Objective-C method in the same class. The problem I get is when I am trying to call self from the C method.
Here is the code :
void SetNotificationListeners(){
    [self fireSpeechRecognition];
}
the error is :
Use of undeclared identifier 'self'
how can I manage this?
You have to pass the instance pointer to the C function:
void SetNotificationListeners(void *uData)
{
    MyClass *obj = (__bridge MyClass *)(uData);
    [obj fireSpeechRecognition];
}
- (void)myMethod
{
    // Call C function from Objective-C method:
    myFunction((__bridge void *)(self));
}
(The "brigde" stuff is needed only if you compile with ARC.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With