iOS : Concepts of Core data


What is Core Data concept? Core data is a robust, full-featured persistence tool provided by Apple for persisting data to the iOS file system. Core Data takes care of all the file system management for you.

Entities and Managed Objects:

Within Xcode, Core Data lets us design our data models visually, without writing code, and stores that data model in the .xcdatamodeld file. Single-click the .xcdatamodeld file, and you will be presented with the data modeleditor.The data model editor gives you two distinct views into your data model, depending on the setting of the control in the lower-right corner of the project window. In Table mode, the elements that make up your data model will be shown in a series of editable tables. In Graph mode, you will see a graphical depiction of the same elements. At the moment, both views reflect the same, empty data model. You create entities here in the data model editor, and then in your code, you create managed objects from those entities.

An entity is made up of properties. There are three types of properties:

  • Attributes: An attribute serves the same function in a Core Data entity as an instance variable does in an Objective-C class. They both hold the data.
  • Relationships: As the name implies, a relationship defines the relationship between entities.
  • Fetchedproperties: Fetched properties allow you to create a query that is evaluated at fetch time to see which objects belong to the relationship. Due to the nature of how fetched properties are constructed and used, they are always one-way relationships. Fetched properties are also the only kind of relationship that lets you traverse multiple data stores.

Persistent store:

It is also referred to as a backing store. By default, a Core Data application implements a backing store as a SQLitedatabase stored in the application's Documents directory. Backing stores can also be implemented as binary flat files, or even stored in an XML format. In almost all situations, you should just leave it as the default and use SQLite as your persistent store.

You generally won't work with your persistent store directly, but rather will use something called a managed object context, often referred to as just a context. The context manages access to the persistent store and maintains information about which properties have changed since the last time an object was saved. The context also registers all changes with the undo manager, meaning that you always have the ability to undo a single change or roll back all the way to the last time data was saved.

Let us follow the below steps to create a new project and see how to include core data features in it.

  • Open Xcode and create a new project.
  • Select the Empty Application template and click next.
  • Name the product TableExample, and select iPhone from the Device Family.
  • Check the Use Core Data checkbox and then click the Next button.
  • When prompted, choose a directory to store your project, and click Create.



iOS sample project << Previous
Next>> iOS : Designing of the Data Model


Support us generously: contact@lessons2 all.com

Our aim is to provide information to the knowledge seekers. 


comments powered by Disqus








Footer1