开发者

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

开发者 https://www.devze.com 2023-02-24 09:55 出处:网络
How can I call a CLASS METHOD on the main thread? Something like: [SomeClass performSelectorOnMainThread:staticM开发者_运维知识库ethod withObject:nil];

How can I call a CLASS METHOD on the main thread? Something like:

[SomeClass performSelectorOnMainThread:staticM开发者_运维知识库ethod withObject:nil];

Please don't tell me to create a regular method to call this class method. That would be an obvious solution, but not clean.

Thanks


[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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号