开发者

How do I make a plain ole C-function an Objective-C selector?

开发者 https://www.devze.com 2023-02-11 05:32 出处:网络
I want to point to a plain ole C-function from Obje开发者_运维技巧ctive-C. Specifically, I am pointing to some OpenGL functions. I want to point to this function from an entry in an NSDictionary.

I want to point to a plain ole C-function from Obje开发者_运维技巧ctive-C. Specifically, I am pointing to some OpenGL functions. I want to point to this function from an entry in an NSDictionary.

So is there a way to turn a C function pointer into a SEL?

Thanks,

Doug


There may be a better way, but why not have an Obj-C method that will call the plain ole C-Function?

You can then make the Obj-C method the SEL that you call.


You could wrap it in an NSValue.

[dictionary setObject:[NSValue valueWithPointer:&myFunction] forKey:theKey];

Then when you extract it later, just call -pointerValue to get a void* pointer back (which you can cast to your function type).

0

精彩评论

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