I’m using this code:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
//saving stuff to NSUserDefaults
});
It works as long as the code is not called twice in rapid succession, at which point I get a crash. All it says is Thread 7: trace for the crash, in a screen for CFRetain.
I’m guessing that my queue should not allow a restart of this routine unless it has finished. But I’m not sure which of the many parameters to change. I do not need it to be high priority, nor am I sure it needs to be the global queue, and to be honest thread programming requires some time for me to nail all this down, so I’m hoping someone can point me in the right direction.
If you want this operation to run asynchronously but always on the same queue (meaning : it’s done in background but never twice at the same time), I recommend you create a
dispatch_queue_tin your class (or somewhere accessible globally, outside the method) :That would go like :
and save always on that queue