I am mixing Objective-C parts in a C ++ project (please do not argue about this, its cross-platform).
Now I want to call some C ++ functions or methods in the correct thread (i.e., Main thread) in cocoa environment.
My current approach transmits function pointers to instance Objective-C (obtained from NSObject) and on it performSelector/ performSelectorOnMainThread.
But performSelectorexpect objects as their arguments, since this can usually be wrapped?
Example:
typedef void(*FnPtr)(void*);
FnPtr fn;
[someInstance performSelector:@selector(test:) withObject:fn];
... where test is declared as:
- (void)test:(FnPtr)fn;
I must add that I just started with Objective-C this week, so if there is a better way, I would also be happy to hear about it.
Also note that I donβt have access to the main loop or to any objects of the application, because the project is a browser plug-in (currently it is only for Safari on Mac).
source
share