Is there a way to create GCD queue that runs on just one thread?
I want to use that queue to handle Core Data operations.
Is there a way to create GCD queue that runs on just one thread?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes; just create the queue with the flag
DISPATCH_QUEUE_SERIAL(this is also the default). But do be careful moving core data operations onto another thread. A givenNSManagedObjectContextmust only be used on a single thread, so you’ll need two contexts, one for your main thread and one for your background thread. Doing this correctly can require some care.You may want to investigate
UIManagedDocument(if this is iOS5), which does much of this work for you. At the very least you should read over its documentation so you learn about its use of parent and child contexts for multithreading.