Câu hỏi phỏng vấn Objective-C
Câu hỏi

What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?

Câu trả lời

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:

  1. Managed objects are instances of classes that inherit from NSManagedObject. They represent entities defined in the Core Data model[4].

  2. 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].

  3. As you modify the properties of a managed object, the context records those changes. You can undo or discard changes if needed[1][4].

  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].

  5. Managed object contexts are thread-safe. You can have multiple contexts...

middle

middle

Gợi ý câu hỏi phỏng vấn

junior

What is the reuseIdentifier used for?

middle

What is the difference between NSDictionary and NSMutableDictionary ?

senior

How to create an abstract class in Objective-C?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào