Executes a block object only once for the lifetime of an application.


void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);



A pointer to a dispatch_once_t structure that is used to test whether the block has completed or not.


The block object to execute once.


This function is useful for initialization of global data (singletons) in an application. Always call this function before using or testing any variables that are initialized by the block.

If called simultaneously from multiple threads, this function waits synchronously until the block has completed.

The predicate must point to a variable stored in global or static scope. The result of using a predicate with automatic or dynamic storage (including Objective-C instance variables) is undefined.

See Also

Executing a Task Only Once


Executes an application-defined function only once for the lifetime of an application.


A predicate for use with the dispatch_once function.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software