Background Thread Object Creation
Intermediate Training Core Data
With the majority of our UI features taken care of already, it's time to discuss how to create Core Data objects in a multithreaded application. In order to maintain the responsiveness of a high quality app, you'll need to perform heavy work on background threads that don't block/hang the UI. In today's lesson, we take a look at how a background thread can be run through GCD (Grand Central Dispatch) to perform a long running task. In the second portion of the lesson, we inspect what happens when you try to use an NSManagedObjectContext that belongs to the main queue on a background thread. Finally, let's go through the code of performing creation of Company objects with performBackgroundTask on NSPersistentContainer.

Comments (5)
Alpensol
5 years ago
Hey Brian, Looking through the documentation I saw that we can can get a private MOC instance with the .newBackgroundThread() call on the persistance container. Working with the context would require the usage of GCD background thread though correct ? Thanks
Brian Voong
5 years ago
moopoints
5 years ago
Hey Brian - after doing this episode I noticed two things that were different with my result: 1) my list of companies after adding 20k companies was not ordered alphanumerically - yours was. 2) Scrolling through my list of companies a lot of the companies randomly reused images as the companyImageView that didn't belong to them (since at this point they also should only have a name and no other information). Any idea as to how either of the two things might have happened?
jesseIOS17
5 years ago
Seeing similar results; variable company names with images sporadically attached.
Christophe Bugnon
5 years ago
Hello Brian, I've two questions. When I press "Do Work" is it working but, my companies didn't create until I restart my appli, and they are not create in order. Ex : first: 1021, second: 23, third: 4542. Did you know why is it working like that ? Best regards.
Christophe Bugnon
5 years ago
Ok I get my answers in the next videos. :D
Cinquain
4 years ago
Fire as usual!
Cinquain
4 years ago
Loving this series
HELP & SUPPORT