Dispatch_once in superclass?

If I call dispatch_once inside the superclass instance method, will it execute once for each subclass? I guess not because the Xcode Grand Central Dispatch (GCD) link says that it "executes the block block once and only once for the life of the application."

+4
source share
2 answers

Your reading of the documentation is correct. This block will be executed only once if you use the same token.

+4
source

Your reading of the documentation is almost correct: dispatch_once () will be executed only once for the lifetime of this variable dispatch_once_t. Since most applications declare this variable as static global, the documentation covers this template. If you have a token that is unique for each instance of the class and starts correctly with zero initialization, then it will be executed for each instance.

+3
source

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


All Articles