Submits a single block to the dispatch queue and causes the block to be executed the specified number of times.


void dispatch_apply(size_t iterations, dispatch_queue_t queue, void (^block)(size_t));



The number of times to execute the block.


The queue on which to submit the block. It is recommended that you specify DISPATCH_APPLY_AUTO for this parameter, as that causes the block to run on a queue whose quality-of-service class is most appropriate for the current execution context.


The application-defined function to be submitted. This parameter cannot be NULL. This block has no return value and takes one parameter:


The current iteration index.


This function submits a block to a dispatch queue for multiple invocations and waits for all iterations of the task block to complete before returning. If the target queue is a concurrent queue returned by dispatch_get_global_queue, the block can be invoked concurrently, and it must therefore be reentrant-safe. Using this function with a concurrent queue can be useful as an efficient parallel for loop.

The current index of iteration is passed to each invocation of the block.

See Also

Executing a Task in Parallel


Submits a single function to the dispatch queue and causes the function to be executed the specified number of times.

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