In the last post, I described how to create the template Core Data App, and showed you a few screenshots. In this one I’ll walk thru the files that are created:
First lest’s look at the structure of the project. We choose a universal app, so we have two storyboards, one for the iPad and one for the iPhone. We gave our class prefix of TAS (for TriangleAppShow) so our basic AppDelegate is created (both header and object source) as TASAppDelegate. Our master and detail views are named TASMasterViewController and TASDetailViewController respectively. I’ve expanded the other subfolders, but won’t go into those files, other than to note that the CoreData.framework is included in your Frameworks folder. The file we will focus on first is the Data Model – CoreDataProject.xcdatamodeld.
Once you select that file, you should see the following screen:
If, you don’t see the above screen, click on the following symbol:
at the bottom right of the main view to switch to this view.
This view allows you to model the database and it’s relationships. The Entity Relationship model describes the Entities, Events, Attributes, and Relationships that make up your data model. The way I like to think of this is as follows:
Entities are tables that store the varies events (rows). Events are made up of Attributes (columns). Events are tied together via Relationships. Relationships are either one to one or one to many. The sample project has only one event , with one attribute and no relationships. You will create a new event every time you select the + button in the app. That event will store a single attribute – the timestamp itself.
The next screenshot shows you the simple definition of the event:
The name is Event – this is how we will reference it in the code of the app. It does not yet have a class (more on this later). Since there are not relationships, we have no Parent Entity. We also have no indexes – this are used to optimize search via predefined and maintained sorts.
If you select that attribute timeStamp the right panel will show you its definition.
We see that this field is optional, with a name of timeStamp. It is currently not indexed, so we assume that events are store in order that they are created. The Attribute type is Date, with no other validations.
So far, pretty simple. In the next post I will look at how the app actually creates each event.