In the previous parts of this series, you learned the basics of core data. Now we are going to learn more about the core data components. Data models in a Core Data application are represented by entities . Entities are composed of attributes and relationships. For more clarity salary is a attribute with a relationship to employee.

Attributes and relationships are called properties. Now we need to bring this entities to the real world, for that we need to represent the entities as managed objects.In Object world, an entity can be thought of as a class and a managed object as an instance of that class.
What is schema ?
A collection of entities with their attributes and relationships represents a schema in a Core Data. This schema is represented by a managed object model. You can create the model using Objective-C code (not recommended) or using the more convenient graphical modeling tool within XCode.
In addition to an entity, a managed object needs a managed object context. Object contexts manage the life cycle of a collection of managed objects. A managed object context needs a persistence store coordinator to manage the persistence of managed objects as well as their retrieval from the store. A store can be a SQLite database, in-memory, or binary file storage. Now we will begin with the major classes in the Core Data framework.
Part 2: Major classes in the Core Data framework
In this part we will learn about the major classes used in the core data framework.
Entity & Attributes:-
Entities are represented by an instance of the NSEntityDescription class. To use the entity we need to create a instance of NSEntityDescription class. The following fragment of code will show how to create an instance of NSEntityDescription class.
Now we need to think about the Attributes. Attributes are represented by the NSAttributeDescription class. To add an attribute, such as name, to an entity. check the following code segment.
In the above code snippet, first we created the instance of the NSAttributeDescription class, after that we set Attribute Name, type and Optional. After creating the attribute we need to bind this nameAttribute to the entity. For that we need to set the property of entity, to set the property of entity we can use setProperties: method . The following code segment will help you to get more clarity.
Managed object model
A managed object model is an instance of the NSManagedObjectModel class. We can create the instance of NSManagedObjectModel in two different ways.
A managed object model is an instance of the NSManagedObjectModel class. We can create the instance of NSManagedObjectModel in two different ways.
Objective-C Code:- using setEntities: method we can bind the entities to the NSManagedObjectModel instance.
Data modeling:- You use a data modeling tool in XCode to graphically build your data model, save it to a file, and load it at runtime into an instance of the NSManagedObjectModel class. The easiest initializer is the mergedModelFromBundles: method. If you pass in nil as the argument, all models in the main bundle are loaded and used to initialize the instance.The following code snippet will help you to understand more.
Data modeling:- You use a data modeling tool in XCode to graphically build your data model, save it to a file, and load it at runtime into an instance of the NSManagedObjectModel class. The easiest initializer is the mergedModelFromBundles: method. If you pass in nil as the argument, all models in the main bundle are loaded and used to initialize the instance.The following code snippet will help you to understand more.
stay tunned …
No comments:
Post a Comment