How to delete an old/unused Data Model Version in Xcode How to delete an old/unused Data Model Version in Xcode xcode xcode

How to delete an old/unused Data Model Version in Xcode


It's a hack, but this worked for me:

  1. Set the Current version of the model in Xcode to one that you want to keep
  2. Remove the .xcdatamodeld from your project (Right-click -> Delete -> Remove Reference Only)
  3. Show the contents of the .xcdatamodeld package in the Finder (Right-click -> Show Package Contents)
  4. Delete the .xcdatamodel file(s) that you don't want anymore
  5. Re-add the .xcdatamodeld file to your project

This eliminates the need to manually modify any of the project metadata files.


I've just found the need to do this. I created a new model version then realised I didn't need it after all. I was surprised to find there was no way of deleting it (that I could find) from Xcode. Still, to remove it I did the following:

First I made sure it wasn't my current model version. Then I went to Finder and found my *.xcdatamodeld file. Right click and Show Package Contents on that. In there you will find the actual model file and can delete it.

This still doesn't remove it from Xcode and it will show red in the Files and Groups. To stop this from happening go back to Finder and Show Package Contents on your main *.xcodeproj file (you may want to make sure you have a backup of this first). In there open up and edit project.pbxproj do a find on your model version name, in my case "interval 8". For me it appeared on two separate lines. I removed these lines and now it's completely removed from Xcode.


This worked for me in XCode 10.3 without the ordering issue occurring when removing the whole model and adding it again:

  1. Select any model version other than the one you want to delete.
  2. From XCode, right-click the .xcdatamodeld file and select 'Show in Finder'.
  3. Close XCode.
  4. In finder, right-click the same file and select 'Show Package Contents'.
  5. Write down the name of the model you want to remove, then from Finder, delete it.
  6. Still in Finder, navigate to the project file (.xcodeproj).
  7. Right-click and open with Atom or any other editor.
  8. From the 'Project' pane open project.pbxproj file.
  9. Remove all lines containing the model name you removed (Example: "ABC 17.xcdatamodel"). You will find two lines similar to the following:

    9D88880323C545B800A789B9 /* ABC 17.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "ABC 17.xcdatamodel"; sourceTree = ""; };

    9D88880323C545B800A789B9 /* ABC 17.xcdatamodel */,

    Note if you find a third line it will be something like:

    currentVersion = 9D88880323C545B800A789B9 /* ABC 17.xcdatamodel */;

    That means it is the currently selected model. Never delete this line. Just change the text to another model version.

  10. Re-open XCode.