How to remove a Core Data Model Version

Core Data can handle several versions of your Model. It’s easy to add a version (via Editor – Add Model Version) and set it active, but it’s not so easy to remove a version you no longer need.

Thankfully there is a way to delete version files which goes a long way to declutter your brain. The secret lies in the fact that the .xcdatamodeld file is actually a Package and can contain more than one file. It’s like the .app extension which isn’t just one file. I never knew this!

To explore, select your versioned .xcdatamodeld file, right-click it and select “Show in Finder”. Once in there right-click it again and select “Show Package Contents”. Surprise – here are all your Model Versions. Before you go on a mad deleting spree, head back to Xcode and do the following:

  1. activate a Model Version that you want to keep (by going to the top level .xcdatamodeld entry, then select it under “Versioned Core Data Model”)
  2. next remove the entire file from your project (just the reference… do not move to trash)
  3. head back to the Finder and delete the files inside the Package you no longer want
  4. go back to Xcode and add the .xcdatamodeld file again

Voila – now all your unnecessary Model Versions are gone. Perhaps in a future version of Xcode there will be an easier way to do this, but as of Xcode 4.6.2 (April 2013) there is not.

Further Reading

Thanks to David Avendasora for this wonderfully simple explanation on Stack Overflow:

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

2 thoughts on “How to remove a Core Data Model Version

  1. So I did the opposite and went on a deleting spree before reading this lol, I deleted my other data model like i wanted to but accidentally deleted the data model i was using for my app and recovered it but now its only showing up in the content file but not as it was before its only written code now.

    How do i get my data model back to normal?

    1. Ouch! They sure don’t make it easy in Xcode, do they? Provided you still have an intact .xcdatamodeld file from a backup, you can simply replace the one in your project via Finder. If it’s no longer showing up in your Xcode project, right-click somewhere in the Project Navigator window and select “Add Files to (your project)”. That should bring it back, and hopefully you’ll be able to select the model version you need.

      Good luck!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.