Adding the NSManagedObjectContext

Next to NSManagedObject, NSManagedObjectContext is the object in the Core Data stack that we’ll most often access. The NSManagedObjectContext is the object we access when we want to save to disk, when we want to read data into memory, and when we want to create new objects. The NSManagedObjectContext is at the top of the Core Data stack in that it’s accessed directly by our code frequently. It’s much less common for us to need to go deeper into the stack.

NSManagedObjectContext can’t be accessed from multiple threads. Each thread that needs access to data should have its own NSManagedObjectContext. This is generally not an issue, since it’s very easy to create multiple contexts as needed for data that has to ...

Get Core Data in Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.