Pick the fix
Importing 50,000 records freezes the UI. Best approach?
Hint 1 of 1
Which queue does the viewContext use?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Import in a background context (or NSBatchInsertRequest) and let the viewContext merge changes
Correct. Work leaves the main queue and the UI updates when it's done.
Why not the others?
- B Loop over the records on the viewContext and save every 100. It still blocks the main queue.
- C Fetch objects on the main context and edit them from a background thread. That breaks queue confinement and causes crashes.
- D Create a new NSPersistentContainer for each batch. Containers are expensive and don't share contexts.