Creating a Core Data Model

Create a data model file to contain your app’s object structure.


The first step in working with Core Data is to create a data model file. Here you define the structure of your application’s objects, including their object types, properties, and relationships.

You can add a Core Data model file to your Xcode project when you create the project, or you can add it to an existing project.

Add Core Data to a New Xcode Project

In the dialog for creating a new project, select the Use Core Data checkbox.

Screenshot showing the Use Core Data checkbox in the options for creating a new Xcode project. The checkbox appears after the language dropdown, and before the checkboxes for including Unit Tests and UI Tests.

The resulting project includes an .xcdatamodeld file.

Screenshot showing the .xcdatamodeld file highlighted in the project navigator.

Add a Core Data Model to an Existing Project

Choose File > New > File and select from the iOS templates. Scroll down to the Core Data section, and choose Data Model:

Screenshot showing the Data Model template in the Core Data section of the file template chooser.

Click Next. Name your model file, and select its group and targets.

Screenshot showing the dialog for saving a data model file. The filename is selected and immediately editable.

An .xcdatamodeld file with the name you specified is added to your project:

Screenshot of Xcode showing the new model file selected in the project navigator.

See Also


Setting Up a Core Data Stack

Set up the classes that manage and persist your app’s objects.

Core Data Stack

Manage and persist your app’s model layer.