Building the Core Data data model

In this recipe we will learn how to use the Core Data Model Editor to build our database schema for our BooksLibrary application.

Getting ready

Following on from our previous recipe, ensure that our BooksLibrary project file is open.

How to do it...

To begin, follow these simple steps as outlined in the following order:

  1. Select the BooksLibrary.xcdatamodel file from Project Navigator.
    How to do it...
  2. Next, click on the +Add Entity button and name this entity Books.
  3. Then click on the +Add Attribute button or alternatively from the Attributes pane.
  4. Create each of the Attributes and Type, as shown in the following table:

    Attribute

    Type

    author

    String

    displayOrder

    Integer 16

    publisher

    String

    title

    String

  5. Save your project using File | Save, as we are done defining our database table schema.

How it works...

The Core Data database model is stored within BooksLibrary.xcdatamodel, located within the BooksLibrary group within the Project Navigator window. In this recipe, we learned how to define the database schema for our SQLite database and create the entities (table) and attributes (fields) that will enable our application to write to these fields within the database, so that it can be queried later.

In our next recipe, we will take a look at how to create the core data model files that will allow us to access the table definitions.

See also

  • The Creating the Core Data model files recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset