Hassy31
Hassy31

Reputation: 2813

using native objective-c method for C callbacks

I want to callback an objective c method from c.

//c 
int gameEngineCallback(int buttontype,void (*callback)(void))

//using above function
gameEngineCallback(roundButton,callback);

//this works fine but I want to call objective c native method instead of this
static void callback(void){

}

Upvotes: 1

Views: 1046

Answers (1)

Vasu Ashok
Vasu Ashok

Reputation: 1413

You Can't Pass Objective c method in C CallBack protoType . but u can redirect to your Objective c Function from the C Call back definition.

EXAMPLE

//Add below line in public declaration of Your Ivar

id myclass; // if ur not Sure about ur class name or u have to redirect to ur delegate class

or 

YourClassName *instanceof class; //(no need to create instance just declartion) 

// before ur call back fires Assign value for ur IVAr in ur init definition

myclass = self ;
or
myclass = delegate;

// use above IVAR like this in Your C callback Function

static void callback(void)
{

[myclass Your Function];

 }

Upvotes: 1

Related Questions