32

I've created a versioned Core Data model in my iOS app, and it has several versions created so far (several .xdatamodel files within the .xcdatamodeld bundle). Before shipping the app, I'm considering deleting these old versions so I can start with a single clean data model - and data loss isn't an issue at this stage.

Is this possible? And what would be the best way to achieve this without simply deleting all Core data files and recreating a new model.

Andrew
  • 655
  • 2
  • 7
  • 11
  • See also similar question here, with even simpler answer: http://stackoverflow.com/questions/7708392/how-to-delete-an-old-unused-data-model-version-in-xcode-4 – charles Feb 15 '12 at 01:31

2 Answers2

48

Deleting the old models means you cannot migrate any existing data stores. I assume you're ok with that given your statement about data loss. If you want to start fresh, you can take the current xcdatamodel, copy it somewhere else (e.g. your Desktop), then delete the xcdatamodeld folder. At this point, you can drag your saved xcdatamodel back into Xcode and re-add it as a non-versioned file.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • 1
    Works great. One extra step: while your xcdatamodel is moved away, open its package contents and delete the old models. Or, just drag back the one model you want from the package contents. – Jeff Mar 26 '13 at 05:41
  • 1
    Updating my comment: "just drag back the one model you want" might cause problems. I got stuck with the code not being able to find my model because what I dragged back was a xcdatamodel, whereas xcdatamodeld is a package (of one or more xcdatamodel). – Jeff Mar 26 '13 at 08:25
  • 1
    I tried to follow the steps you outlined but it made the xcdatamodelId uneditable in Xcode. These steps worked better for me: http://stackoverflow.com/a/8107530/127036 – Vibhor Goyal Jun 05 '13 at 23:59
0

If you want to get rid of old versions of the data model

(Note: make sure you copy the Data model file and save it somewhere in case something goes wrong)

Five Step solution

  1. Select .xcdatamodeld file in Xcode, make sure you have the latest version is set as the current data model.
  2. Right, Click Show in finder if you don't see all your versions right click again and show package contents.
  3. Delete all the version except the latest.
  4. Jump back to Xcode and now delete the .xcdatamodeld file just remove reference don't move to trash.
  5. Add the file back again

Voila it's done

Rein rPavi
  • 3,368
  • 4
  • 22
  • 32