Learn Courses My Dashboard

Can somebody help me to use DispatchGroup in swift?

I don’t know how to use DispatchGroup for a nested loop inside closure…I have searched everywhere for a good explanation. Could somebody edit the code below according to my goal.

My goal is to execute the print statements in below given order.

  2. PROCESSING…(several times according to loop)

what I currently gets is :

  3. PROCESSING…(several times according to loop).

question link : https://stackoverflow.com/questions/67402034/can-somebody-add-dispatchgroup-correctly-in-the-below-given-code-which-is-nested

hello, did you perhaps put the “processing complete” on the same closure? , it should it in the “onCompleted” or something similar closure and not alongside your loop

The response you got on stackoverflow to your question is typical of the adversarial (argumentative) nature of the site.

Some of the users with a high reputation are just totally obnoxious and the user ‘vadian’ is typical of that. His way is to say, " DispatchGroup makes no sense in the context of a single asynchronous task" rather than include an explanation as to why he has that view. Totally unhelpful.

That said, I have no insight into how a DispatchGroup is used other than what the Apple Documentation describes.


What vadian is saying is that the task you have is effectively a single asynchronous task so placing that in a DispatchGroup is no advantage since you are not dealing with multiple tasks that need to be completed as a prerequisite to some other activity.

This is an article from Donny Wals on DispatchGroup which may help you understand their use.