have a view that loads and a serial dispatch queue that is created, loads a ton of stuff in the background and works great. Problem is when I navigate back and forth to that view a new queue is created again and then I have multiple things doing the exact same work.
- (void)viewDidLoad {
dispatch_queue_t myQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
dispatch_async(myQueue, ^{
//function call to a helper outside the scope of this view
});
}
How do I prevent this from happening?
EDIT:
creating my own queue was not necessary so I change my code – same problem still exists.
So here is a way to achieve what I really desire, prevent my dispatched queued items from running when my view is popped from the navigation stack:
I simple wrap this code around my code that is running in my dispatched queue:
This came from watching the Blocks & Multithreading video here by Stanford:
http://itunes.apple.com/us/itunes-u/developing-apps-for-ios-hd/id395605774
great video, helped lot.