#define ensureInMainThread(); if ([NSThread currentThread] != [NSThread mainThread]) { [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO]; return; }
It can only be used from methods that accept (and return) no parameters.
Now you can have pretty code like this
- (void) msgReceived {
ensureInMainThread();
Beware that using code like this might indicate that you are completely lost in a sea of threads. If you have no idea why you need this method, you should go back to your code and figure it out.
No comments:
Post a Comment