Core Data – I
• History • Fundamentals • Under the Hood • Demo
Enterprise Object Framework
History -wiki • Early 1990, NeXT created an Abstraction above databases (DBKit-92) • DBKit failed, in 94 a complete rewrite came as form of EOF (4 people team!) – read only • EOF2.0 in 95 – Context Editing • EOF was useful for WWW and web apps • In 96 first OO webserver WebObjects launched with EOF at its heart • 2005, EOF returns to OSX Tiger as Core Data • June 2009 Released for iPhone OS 3.0
EOF -wiki • Database tables are mapped to classes. • Database columns are mapped to class attributes. • Database rows are mapped to objects (or class instances) • Can leverage inheritance • EO is a class which models a physical or conceptual object in the business domain.
Fundamentals
What is Core Data –Apple Doc. • Core Data is a schema-driven object graph management and persistence framework. Fundamentally, Core Data helps you to save model objects (in the sense of the model-view- controller design pattern) to a file and get them back again. This is similar to archiving, but Core Data offers much more than that.
What is Core Data –Apple Doc. • Provides an infrastructure for managing all the changes to your model objects. This gives you automatic support for undo and redo, and for maintaining reciprocal relationships between objects.
What is Core Data –Apple Doc. • Allows you to keep just a subset of your model objects in memory at any given time. This is especially important on iOS where conserving memory is critical. • Allows you to maintain disjoint sets of edits of your objects. This is useful if you want to, for example, allow the user to make edits in one view that may be discarded without affecting data displayed in another view.
What is Core Data –Apple Doc. • Uses a schema to describe the model objects. You define the principal features of your model classes—including the relationships between them—in a GUI-based editor. This provides a wealth of basic functionality “for free,” including setting of default values and attribute value validation.
What is Core Data –Apple Doc. • Has an infrastructure for data store versioning and migration. This lets you easily upgrade an old version of the user’s file to the current version.
Core Data Components User Managed Object Context (managed object) (managed object) Persistent Store Coordinator Storage Storage Storage
Initialization Data Model (.momd) Persistent Sore (sqlite/xml...) Managed Object Context
In Action User Code NSFetchRequest MOMOC Persistent Sore Coordinator n1 Persistent Sore momd
Under the Hood • Core Data applications requires an Object Model (NSManagedObjectModel) – Model defines entities (NSEntityDescription) Entities have three kind of Properties (NSPropertyDescription): • Attributes (NSAttributeDescription) • Relationships (NSRelationshipDescription) • Fetched Properties (NSFetchedPropertyDescription)
Demo

Pune-Cocoa: Core data - I

  • 1.
  • 2.
    • History • Fundamentals •Under the Hood • Demo
  • 3.
  • 4.
    History -wiki • Early1990, NeXT created an Abstraction above databases (DBKit-92) • DBKit failed, in 94 a complete rewrite came as form of EOF (4 people team!) – read only • EOF2.0 in 95 – Context Editing • EOF was useful for WWW and web apps • In 96 first OO webserver WebObjects launched with EOF at its heart • 2005, EOF returns to OSX Tiger as Core Data • June 2009 Released for iPhone OS 3.0
  • 5.
    EOF -wiki • Databasetables are mapped to classes. • Database columns are mapped to class attributes. • Database rows are mapped to objects (or class instances) • Can leverage inheritance • EO is a class which models a physical or conceptual object in the business domain.
  • 6.
  • 7.
    What is CoreData –Apple Doc. • Core Data is a schema-driven object graph management and persistence framework. Fundamentally, Core Data helps you to save model objects (in the sense of the model-view- controller design pattern) to a file and get them back again. This is similar to archiving, but Core Data offers much more than that.
  • 8.
    What is CoreData –Apple Doc. • Provides an infrastructure for managing all the changes to your model objects. This gives you automatic support for undo and redo, and for maintaining reciprocal relationships between objects.
  • 9.
    What is CoreData –Apple Doc. • Allows you to keep just a subset of your model objects in memory at any given time. This is especially important on iOS where conserving memory is critical. • Allows you to maintain disjoint sets of edits of your objects. This is useful if you want to, for example, allow the user to make edits in one view that may be discarded without affecting data displayed in another view.
  • 10.
    What is CoreData –Apple Doc. • Uses a schema to describe the model objects. You define the principal features of your model classes—including the relationships between them—in a GUI-based editor. This provides a wealth of basic functionality “for free,” including setting of default values and attribute value validation.
  • 11.
    What is CoreData –Apple Doc. • Has an infrastructure for data store versioning and migration. This lets you easily upgrade an old version of the user’s file to the current version.
  • 12.
    Core Data Components User ManagedObject Context (managed object) (managed object) Persistent Store Coordinator Storage Storage Storage
  • 13.
  • 14.
  • 15.
    Under the Hood •Core Data applications requires an Object Model (NSManagedObjectModel) – Model defines entities (NSEntityDescription) Entities have three kind of Properties (NSPropertyDescription): • Attributes (NSAttributeDescription) • Relationships (NSRelationshipDescription) • Fetched Properties (NSFetchedPropertyDescription)
  • 16.

Editor's Notes

  • #5 Legacy databases can be easily wrapped in EOF
  • #6 Legacy databases can be easily wrapped in EOF
  • #16 NSManagedObjectModel has references to zero or more NSEntityDescription objects. Each NSEntityDescription has references to zero or more NSPropertyDescription objects. NSPropertyDescription is an abstract class with three concrete implementations This small set of classes is enough to define any object model you will use when working on your Core Data projects.