Objective C - Calling a class method on the main thread?

谁说胖子不能爱 提交于 2019-12-03 13:03:51
[SomeClass performSelectorOnMainThread:staticMethod withObject:nil waitUntilDone:NO];

Yes, performSelectorOnMainThread:withObject:waitUntilDone: is not a class method.

Yes, it is an instance method on NSObject.

Yes, all Class objects are instances of NSObject. (I'm not kidding!)


You could also do:

dispatch_async(dispatch_get_main_queue(), ^{
  [SomeClass doClassyThingWithObject:object1 andDiddleyDoo:foo];
});

How about:

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:[SomeClass class] selector:@selector(SomeClass) object:nil];
[[NSOperationQueue mainQueue] addOperation:operation];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!