iOS - Objective-C Callback for C++

by digipine posted Nov 01, 2017
?

Shortcut

PrevPrev Article

NextNext Article

ESCClose

Larger Font Smaller Font Up Down Go comment Print

// C++
typedef (void)(*MyCallbackFPtr)(int special, void *ctx);

void MyClass::SetCallback(MyCallbackFPtr fptr, void *ctx) { ... }

// to call it
   callback(42, mCtx);

 

// ObjC
void MsgSendCallback(int special, void *ctx) {
   [(id)ctx someMethodWithInt:special];
}

// ...
   cppMyClassInstance->setCallback(MsgSendCallback, self);

TAG •