I have a pure C++ class that needs to retrieve an int value from some Objective-C instance method.
I understand that C++ cannot call Objective-C methods directly.
I have an Objective-C++ class that allows me to work with Objective-C and also to pass data to my pure C++ class.
However, I have not figured out a way to allow the pure C++ class to request the int value be computed and retrieved. In other words, the pure C++ needs to be able to retrieve that value whenever it needs to (via a function pointer, or whatever).
Anyone know how this is accomplished?
C++ can definitely call Objective-C code. Store the code that communicates in a .mm file instead of .cpp, and Xcode will do the rest for you.
.mm files store Objective-C++ code, which is why it works.
[Edit]
You probably have some business logic in C++, and want to combine that with your UI in Objective-C, right? Your business logic is probably shared across multiple platforms, which is why you can’t just compile all your code as Objective-C++.
That’s why you can basically “wrap” your Objective-C code in an Objective-C++ wrapper.