Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Core Data Fundamentals

Core Data Fundamentals

I gave a talk on Core Data in a Nutshell and its concurrency rules.


Ajith R Nayak

September 22, 2021


  1. Core Data Fundamentals - @ajithrnayak

  2. Core Data Vs Developers

  3. Core Data Stack NSPersistentStoreCoordinator SQLite NSPersistentContainer NSManagedObjectContext NSPersistentStore NSManagedObjectModel App

  4. NSManagedObjectContext • Like a scratchpad • fetch, change, add and

    delete • Create more than one contexts • Updates persistent store
  5. Concurrency policies ConcurrencyType NSPrivateQueueConcurrencyType 
 (background queue) NSMainQueueConcurrencyType 

    main queue)
  6. perform(_:) • asynchronous method • gets wrapped in a autorelease

    pool. performAndWait(_:) • synchronous method • will block the calling thread • does not wrap the block in an 
 autorelease pool.
  7. Summary • A managed object context is tied to a

    serial queue. • Create only two contexts for simplicity. • Concurrency types are two but contexts can be many. • Context executes on a “private” queue. • Performance heavy operations should be performed on the background queue. • Don’t pass NSManagedObject instances between queues. • To avoid unnecessary saves, be aware of automatically triggered broadcasts.
  8. Thank you