Reputation: 4173
may sound like a stupid question, but, out of curiosity, is it possible to pause a for loop in objective c?
for example:
for (NSManagedObject *a in sortedArray)
{
//do something that takes time, for example download something
}
in the above example the for loop would start all downloads at the same time, because after starting the download (or whatever action you put there) it would go to the next object in the array. what if i would like to wait till the download is finished? is there a way to pause the download or would i have to restart the for loop skipping the already downloaded ones?
Upvotes: 0
Views: 602
Reputation: 11834
There are several ways to achieve this. One way would be using Grand Central Dispatch semaphores. Read about dispatch semaphores here: http://www.mikeash.com/pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html.
Also check this question on SO, might be exactly what you need: How can I signal one thread to wait until a download is finished and after that pass the data to waiting thread
Upvotes: 1
Reputation: 46533
You need to use NSThreads / GCD for multiple processes.
But you will have to deal with synchronous and asynchronous methods and sometimes with there call backs.
Upvotes: 0