I've got some code in
https://github.com/dpp/LispHaskellIPad that uses an FFI call into ObjC code that invokes a function on the UI thread.
In Haskell:
runOnMain :: IO () -> IO ()
runOnMain todo = do
func <- funky
dispatchFunc func
where funky = mkStrCB $ \v -> do
todo
And in ObjC:
void dispatchFunc(void (*fp)(void*)) {
// dispatch_async_f(dispatch_get_main_queue(), NULL, fp);
id runner = [[PerformOMatic alloc] init];
[runner setFunc:fp];
[runner run];
}
And:
#import "PerformOMatic.h"
@implementation PerformOMatic
- (void)run {
[self performSelectorOnMainThread:@selector(reallyDoIt:) withObject:self waitUntilDone:TRUE];
}
- (void)reallyDoIt:(id)ignore {
whatToDo(NULL);
releaseMe(whatToDo);
[self dealloc];
}
- (void)setFunc:(void *)func {
whatToDo = func;
}
@end
Pardon the extremely ugly code, I'm a Haskell newbie and my ObjC skills are 20 years old.