I have an objective-c class whose methods I only ever want to be called from the main thread.
I could achieve this by adding something like this to each selector:
- (void) exampleSelector: (id) param {
if (![NSThread isMainThread]) {
[self peformSelectorOnMainThread:@selector(exampleSelector:) withObject:param waitUntilDone:YES];
return;
}
// Do stuff it's not safe to do outside the main thread
}
However it seems a bit of a pain to add this to every single selector. Is there any way I can automatically intercept all calls to objects of this class, check what thread it's in, and use performSelectorOnMainThread if it's not the main thread?