With Xcode 9, you can get analyzer warnings if the compiler is able to figure out that you're calling UIKit from a background thread.
Is there a way to get these for my own methods?
For example:
@interface MyObject
- (void)doThingOnMainThread NS_MAIN_THREAD_ONLY;
// where NS_MAIN_THREAD_ONLY is a thing I just made up, as far as I know
@end
Elsewhere:
- (void)otherMethod {
MyObject *myObject = [MyObject sharedObject];
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// I'd like a warning here, if possible!
[myObject doThingOnMainThread];
});
}