Reputation: 12954
I want to point to a plain ole C-function from Objective-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
Upvotes: 0
Views: 114
Reputation: 185861
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).
Upvotes: 1
Reputation: 8742
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.
Upvotes: 2