开发者

Accessing ivars of an objective-c class within c++ function

开发者 https://www.devze.com 2023-01-10 08:56 出处:网络
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 开发者_C百科in c++, and I therefore cannot access th

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 开发者_C百科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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消