Core Data
Changes in iOS10
G. Abhisek
• Core Data Concepts.
• Changes in Core Data.
Contents:
• What is Core Data?
• Core Data Stack:
Managed Object Model
Persistent Store Coordinator
Managed Object Contexts
Core Data Concepts
What is Core Data?
• Its not a database.
• Its a framework - Manages model layer objects in
application.
• Three types of files are generated when core data for an
application is enabled :
- .sqlite (Database file)
- .sqlite-shm (Shared Memory)
- .sqlite-wal (Write ahead log)
Core Data Stack
• Managed Object Model - Data model of application.
• Persistent Store Co-ordinator - The one which persists
our data in the database.
• Managed Object Context - Collection of model objects.
Core Data Changes
• Persistent Containers
• Query Generations
• Concurrency Improvements
Persistent Containers
• It creates a managed object model, and a managed object
context.
• Provides several properties and methods to interact with
the Core Data stack.
• Provides a description about the persistent store, its
configuration, and whether it is a read-only persistent
store.
• Initialise Persistent Store Container:
let persistentContainer = NSPersistentContainer(name: "MyApplication")
• Get the description of Persistent store:
let persistentStoreDescription = NSPersistentStoreDescription(url: url)
• Add Persistent Store to Persistent Store Coordinator

Faulting
• When we fetch any entity from from Core Data database,
we are returned back with not a fully initialised managed
object, if its not required, rather it returns a kind of
placeholder for the particular managed object’s instance.
• When faults are inaccessible or faults are not fulfilled, we
encounter an exception (crash in iOS8 & exception iOS9)
• Resolve this issue by:
Setting shouldDeleteInaccessibleFaults to proper value.
Query Generations
• As of iOS 10 & 10.2, assigns a query generation to a
managed object context.
• It means it interacts with a snapshot of the data stored in
the persistent store.
• Any changes in the data base won’t affect the snapshot
thereby avoiding a possible case of faults.
Concurrency Improvements
• Earlier to iOS10, Persistent Stores locked themselves if
different contexts accessed them from different threads,
which results in performance issues, and slower Core
Data procedures.
• As of iOS 10, the persistent store is not allowed to lock
itself away, and the query is directly moved to the SQLite
database.
Thank You

Core data ios10changes

  • 1.
    Core Data Changes iniOS10 G. Abhisek
  • 2.
    • Core DataConcepts. • Changes in Core Data. Contents:
  • 3.
    • What isCore Data? • Core Data Stack: Managed Object Model Persistent Store Coordinator Managed Object Contexts Core Data Concepts
  • 4.
    What is CoreData? • Its not a database. • Its a framework - Manages model layer objects in application. • Three types of files are generated when core data for an application is enabled : - .sqlite (Database file) - .sqlite-shm (Shared Memory) - .sqlite-wal (Write ahead log)
  • 5.
    Core Data Stack •Managed Object Model - Data model of application. • Persistent Store Co-ordinator - The one which persists our data in the database. • Managed Object Context - Collection of model objects.
  • 7.
    Core Data Changes •Persistent Containers • Query Generations • Concurrency Improvements
  • 8.
    Persistent Containers • Itcreates a managed object model, and a managed object context. • Provides several properties and methods to interact with the Core Data stack. • Provides a description about the persistent store, its configuration, and whether it is a read-only persistent store.
  • 9.
    • Initialise PersistentStore Container: let persistentContainer = NSPersistentContainer(name: "MyApplication") • Get the description of Persistent store: let persistentStoreDescription = NSPersistentStoreDescription(url: url) • Add Persistent Store to Persistent Store Coordinator

  • 10.
    Faulting • When wefetch any entity from from Core Data database, we are returned back with not a fully initialised managed object, if its not required, rather it returns a kind of placeholder for the particular managed object’s instance. • When faults are inaccessible or faults are not fulfilled, we encounter an exception (crash in iOS8 & exception iOS9) • Resolve this issue by: Setting shouldDeleteInaccessibleFaults to proper value.
  • 11.
    Query Generations • Asof iOS 10 & 10.2, assigns a query generation to a managed object context. • It means it interacts with a snapshot of the data stored in the persistent store. • Any changes in the data base won’t affect the snapshot thereby avoiding a possible case of faults.
  • 12.
    Concurrency Improvements • Earlierto iOS10, Persistent Stores locked themselves if different contexts accessed them from different threads, which results in performance issues, and slower Core Data procedures. • As of iOS 10, the persistent store is not allowed to lock itself away, and the query is directly moved to the SQLite database.
  • 13.