SACC

/ / navigation

Introduction

Core Data Exercise


// Introduction



Core Data provides an easy to use wrapper around SQL that lets you spend your time thinking in objects instead of queries.


What you will do

You are going to use Core Data to create and use the persistent data in an application.

You are going to build an application called ’Conference’. This application will help users manage which sessions they want to attend at a conference. For each track in the conference you will display a list of sessions in that track. Users then select the sessions they want to attend.

The Conference application has four screens. The opening screen displays a list of tracks. The user can add and delete tracks and when the edit button is pushed selecting a track takes you to the editing screen for the track information.

The list of tracks displayed here comes from Core Data, specifically the managed object context. All the Track objects are fetched from persistent storage and that list becomes the underlying data model for this table. Tracks can be added to the list by clicking on the ’+’ button in the top left hand side. When that button is clicked you will call on Core Data to make the new object and place it into the managed object context. Clicking any of the red ’-’ buttons on one of the rows will allow the user to delete the object. If an object is deleted, you will remove it from your managed object context. After the changes are made as you’d expect you persist them by calling the save: on the managed object context.

The next screen allows the user to edit the track’s name and abstract. As the text of the name or abstract for a track is edited the track’s properties are updated. These changes too are registered by the managed object context. You don’t have to code that, the managed object context is watching your objects and makes note of any changes. When the user finishes here the changes are persisted again.

When the track list is not in editing mode, selecting a track takes the user to the list of sessions for that track.

Pressing the ’+’ button creates a new Session and adds it to the managed object context.

And finally selecting a particular session takes you to the editing screen for that track.

When the user is finished making changes to the session information the text is placed back on the session object, and the managed object context makes note of the changes since its watching the session object. In fact the MOC is watching all objects that are in it. Any change you make to any object that you get from an MOC are catalogued by the MOC so they can be persisted when the save: method is called.