How to Create an iOS Project with Core Data Support in Xcode

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence. In this post, you can learn how to create an iOS project with Core Data support in Xcode step by step.

Firstly, choose File > New > Project from the Xcode menu.

Choose File > New > Project

Next, select App template in the iOS tab.

Select App template in the iOS tab

Then, check the Use Core Data option, and enter your product name. In addition, we select SwiftUI for interface and select SwiftUI App for Life Cycle.

Check the Use Core Data Option

Finally, the project with Core Data support is created. In the project explorer, you can found two important files. One is Data Model file whose extension name is xcodemodelid, the other is Persistence.swift which contains the definition of PersistenceController.

Project Structure

In Core Data, we define entities in the Data Model file and generate custom test data in PersistenceController. In another post How to Add Core Data Support to An Existing Project, we discussed the way to define entities and generate custom test data detailed. Moreover, you can learn the differences between Core Data with SQLite in the post 4 Differences Between Core Data and SQLite You Should Know, it can help you know Core Data easily.


Leave a Reply

Your email address will not be published. Required fields are marked *