What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?
What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?
The purpose of NSManagedObjectContext
in Objective-C Core Data is to manage the lifecycle of managed objects and provide a scratchpad for working with them[1][4]. It acts as a central hub for creating, updating, deleting, and saving managed objects[4].
Here's how NSManagedObjectContext
works:
Managed objects are instances of classes that inherit from NSManagedObject
. They represent entities defined in the Core Data model[4].
When you create a new managed object, you do so within the context of an NSManagedObjectContext
. The context keeps track of the object's state and changes[1][4].
As you modify the properties of a managed object, the context records those changes. You can undo or discard changes if needed[1][4].
When you're ready to save changes, you call save:
on the context. This persists the changes to the underlying persistent store coordinator[3][4].
Managed object contexts are thread-safe. You can have multiple contexts...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào