Objective C - calling a class method in the main thread?

How can I call CLASS METHOD in the main thread? Sort of:

 [SomeClass performSelectorOnMainThread:staticMethod withObject:nil]; 

Please do not tell me to create a regular method to call this class method. This would be an obvious solution, but not a clean one.

thanks

+6
source share
2 answers
 [SomeClass performSelectorOnMainThread:staticMethod withObject:nil waitUntilDone:NO]; 

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

Yes, this is an instance method on NSObject .

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


You can also do:

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

What about:

 NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:[SomeClass class] selector:@selector(SomeClass) object:nil]; [[NSOperationQueue mainQueue] addOperation:operation]; 
+1
source

Source: https://habr.com/ru/post/885768/


All Articles