Câu hỏi phỏng vấn iOS
Câu hỏi

Describe managed object context and...

Câu trả lời

A managed object context (represented by an instance of NSManagedObjectContext) is a central component in the Core Data stack of an iOS application. It acts as an in-memory "scratchpad" for managing a collection of managed objects, which represent data from one or more persistent stores.

Key Functionalities of Managed Object Context

  1. Life-Cycle Management:

    • Validation: Ensures that the data conforms to the model's constraints before saving.
    • Inverse Relationship Handling: Automatically maintains the integrity of relationships between objects.
    • Undo/Redo: Provides an undo manager to allow for undoing and redoing changes made to the objects within the context[2][4][7].
  2. Fetching and Managing Data:

    • Fetch Requests: Allows for retrieving objects from the persistent store based on specified criteria.
    • Insert, Update, Delete: Supports creating new objects, modifying existing ones, and deleting objects from the context.
    • Save: Commits changes made in the context to the persistent store[2][4][7].
  3. Concurrency:

    • Concurrency Types: Supports different concurrency patterns (main queue, private queue) to manage data access across multiple threads safely. This helps in performing background tasks without blocking the main thread, thus improving app performance[2][5][10].
  4. Notifications:

    • Context Notifications: Posts notifications at various points (e.g., when objects are inserted, updated, or deleted) that can be observed by other parts of the application to react to changes[6][12].
  5. Object Graph Management:

    • Object Graph: Manages a collection of objects that form an internally consistent view of the data. Changes to objects in the context are tracked and can be committed or discarded as needed[2][4][7].

Example Usage

When you fetch objects from a persistent store, they are brought into the managed object context where you can modify them. These changes remain in the context until you explicitly save them, at which point they are written back to the persistent store. T...

senior

senior

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

junior

What are different ways that you can specify the layout of elements in a UIView ?

middle

What are some pros and cons of Core Data?

middle

Explain code signing for iOS apps

Bình luận

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

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