开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜