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

后端 未结 2 1102
旧时难觅i
旧时难觅i 2021-02-15 17:50

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

[SomeClass performSelectorOnMainThread:staticMethod withObject:nil];
2条回答
  •  有刺的猬
    2021-02-15 18:43

    [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];
    });
    

提交回复
热议问题