Learn Courses My Dashboard

Adding a NSPersistentContainer in a existing project

How do you add a NSPersistentContainer in a existing project in Xcode-13?

@And_12

Welcome to the community.

This tutorial may help.

Can I just copy and paste a Persistent file to my project? will that work

@And_12

If you mean copy an .xcdatamodeld file from another project I don’t think there is any advantage in doing that since you have to configure it to suit the project data structure that you currently have.

If you are not familiar with Core Data then I suggest that you watch the tutorial I posted to give yourself a good grounding in how it works.

Sorry for bothering LAST QUESTION LOL - is it possible to put a presistent file in a existing project? if you have a .xcdatamodeld (which I have)

Yes it is. There is no rule that says that you have to create a project with Core Data checked at the point where you create it.

You can either add a brand new Data Model file through the Xcode Menu - File > New then scroll down to the template group titled “Core Data” and select the object named Data Model, name it and away you go.

Alternatively drag in the file you already have (from your Desktop I assume) and drop it in your Project Navigator pane (the one on the left). When the dialog box pops up, make sure that you check “Copy items if needed” and “Add to targets”.

Thank you so much for your time!