Skip to content

Instantly share code, notes, and snippets.

@devahmedshendy
Last active January 16, 2024 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devahmedshendy/0c13af56a08b2a03303d33ae73ba17fa to your computer and use it in GitHub Desktop.
Save devahmedshendy/0c13af56a08b2a03303d33ae73ba17fa to your computer and use it in GitHub Desktop.
Core Data Fundamentals - CheatSheet (Simple)

Core Data Fundamentals - CheatSheet (Simple)

Here, I will save basic coredata information for anyone/me would like a quick refresh for these fundamentals from time to time.

What is Core Data

  • Core Data is not a database, but instead it manages an Object Graph.

Multithreading

  • NSManagedObject and NSManagedObjectContext in Core Data are not thread-safe.

  • Core Data avoids data race issues by operating on NSManagedObject instances and NSManagedObjectContext instances in a serial queue.
    This is why we need to place the operation code within the closures of perform or performAndWait.

  • Developers should perform operations on the main thread queue for the view context and the managed object instances registered within it. Similarly, we should perform operations on the serial queue created by the private context for private contexts and the managed objects registered within them.

Several Tips on Core Data Concurrency Programming

  • Enable Core Data Concurrency Debugging Parameters
    To void issues like .......... to be continued

Misc

  • ModelContext of SwiftUI is like a wrapped version of NSManagedObjectContext

References:

@devahmedshendy
Copy link
Author

NSPersistentContainer Class

  • It encapsulates the details of setting and managing a core data stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment