Slide 1

Slide 1 text

Core Data Fundamentals - @ajithrnayak

Slide 2

Slide 2 text

Core Data Vs Developers

Slide 3

Slide 3 text

Core Data Stack NSPersistentStoreCoordinator SQLite NSPersistentContainer NSManagedObjectContext NSPersistentStore NSManagedObjectModel App

Slide 4

Slide 4 text

NSManagedObjectContext • Like a scratchpad • fetch, change, add and delete • Create more than one contexts • Updates persistent store

Slide 5

Slide 5 text

Concurrency policies ConcurrencyType NSPrivateQueueConcurrencyType 
 (background queue) NSMainQueueConcurrencyType 
 (application’s main queue)

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

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.

Slide 8

Slide 8 text

Thank you