How can I call a CLASS METHOD
on the main thread?
Something like:
[SomeClass performSelectorOnMainThread:staticMethod 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
In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals. '@' is used a lot in the objective-C world.
When an application is launched in Android, it creates the first thread of execution, known as the “main” thread. The main thread is responsible for dispatching events to the appropriate user interface widgets as well as communicating with components from the Android UI toolkit.
[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];
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With