Monday, August 13, 2012

The Core Data Stack: 
is the term used to describe a collection of Core Data framework objects that  work together to get
modeled objects from and save data to a persistent store—the file where your data is stored. Conceptually, a persistent store is like a database, with tables and records.

Three main important stack or pillar of core data:

1.Managed object Model :We think this is a core database schema . It is main class that hold the definition of all object(also called  entities ), those used in database storing.
Usually, you will use the visual editor you just peeked at to set up what objects are in the database, what their attributes, and how they relate to each other.

2.Persistent Store co-coordinator:  This is stand for database connection Here’s where you set up the actual names and locations of what databases will be used to store the objects, and any time a managed object context needs to save something it goes through this single coordinator.

3.Managed Object Context: Managed object context take the responsibility  for inserting, deleting and modify  object definition .  when we perform any action inserting, deleting and modify it send to Persistent store Co-coordinator.

 Managed Objects and the Managed Object Context: 

A managed object is an instance of NSManagedObject or of a subclass of NSManagedObject. Conceptually, it’s an object representation of a record in a table in a database, so it’s a model .
(in the sense of the
model-view-controller design pattern) object that is managed by Core Data. Managed objects represent the data you operate on in your application—for example departments and employees in a human resources application;shapes, text areas, and groups in a drawing application; albums, artists, and tracks in a music management application. A managed object is always associated with a managed object context.
The managed object context is an instance of NSManagedObjectContext. A context represents a single object space, or scratch pad, in an application. Its primary responsibility is to manage a collection of managed objects. These objects form a group of related model objects that represent an internally consistent view of one or more persistent stores. The context is a powerful object with a central role in your application, with responsibilities from life-cycle management to validation, relationship maintenance, and undo/redo.
When you create a new managed object, you insert it into a context. You fetch existing records in the database into the context as managed objects. (Fetching is discussed in greater detail in “Fetching Events” Any changes you make (whether insertion or deletion of complete objects, or manipulation of property values) are kept in memory until you actually commit them to the store by saving the context.
The Managed Object Model:A managed object model is an instance of NSManagedObjectModel. It’s an object representation of a schema
that describes your database, and so the managed objects you use in your application. A model is a collection of entity description objects (instances of NSEntityDescription). An entity description describes an entity (a table in a database) in terms of its name, the name of the class used to represent the entity in your application, and what properties (attributes and relationships) it has.
Every managed object has a reference to the entity of which it is an instance. 
Core Data uses the model to map between managed objects in your application and records in the database. It’s important to be aware that if you change the schema in your application, Core Data won’t be able to read stores you created using the previous model.

Persistent Store Coordinator :

The persistent store coordinator plays a central role in how Core Data manages data; however, you don’t often interact with the coordinator directly when you use the framework. This section describes the persistent store coordinator in detail, so if you prefer you can skip it and refer to it later as necessary. (The persistent store coordinator is also described in Core Data Basics in the Core Data Programming.
A persistent store coordinator is an instance of NSPersistentStoreCoordinator. It manages a collection
of persistent object stores. A persistent object store represents an external store (file) of persisted data. It’s the object that actually maps between objects in your application and records in the database. There are different classes of persistent object store for the different file types that Core Data supports. You can also implement your own if you want to support a custom file type—see Atomic Store Programming Topics . To learn more about persistent stores and the different types, see Persistent Store Features in Core Data Programming Guide

 

Core Data Tutorial

Introduction: 

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 .
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 More :

● Provides an Graphical way 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.
● 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.
● 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.
● 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.
● Has an infrastructure for data store version and migration. This lets you easily upgrade an old version of the user’s file to the current version.

Important: Core Data is not an entry-level technology. Before starting to use Core Data, you must understand
the basics of iOS application development, including:
● How to use Xcode and Interface Builder
● Fundamental design patterns such as model-view-controller and delegation
● How to use view controllers, navigation controllers, and table views