views:

23

answers:

2

I have an objective-c class, which has a string ivar which I need to change when a callback function is called. The trouble is that the callback is in c++, and I therefore cannot access the ivars of the objective-c class in that c++ function. The callback must be in c++ that, cannot change. I realize that there are other ways this could be done ie a global variable which is set by that function and read by my class, or a wrapper c++ class which contains the function and a string and is a member of my objective-c class. However I feel that simply setting the ivar within the callback would be the simplest and cleanest way to do it. Anyone know of a way to do such a thing?

A: 

I would use a getter/setter on the Objective-C class and pass it to the function as context info.

Wevah
A: 

This seems you need to code c++ and objective C in the same code

so just add extension of the file as .mm and just can write c++ and objective c easily.

Arjit