Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a C++ method as an ObjC selector?

Tags:

objective-c

I will like to do some kind of forwarding in my mixed C++/ObjC project.

My logic is in C++, and I want to provide a method that belongs to a C++ object instance as a selector to objC. Is there anyway to do this?

Mainly the question is, Is there anyway to fake a C++ method into a selector :), to give it to ObjC and let it be called back?.

Thanks in advance, Anoide.

like image 518
Anoide Avatar asked Oct 26 '22 14:10

Anoide


1 Answers

It is impossible to get a selector for a C++ method as these are not managed by the Objective-C runtime. You can, however:

  • Use a normal C++ function pointer to implement a callback
  • Or: Create an Objective-C method (best would be a class method) to wrap the call to your C++ method. You can use the selector for this function then.
like image 97
Johannes Rudolph Avatar answered Nov 15 '22 10:11

Johannes Rudolph