25

I made a lightweight migration that I decided I don't want anymore. Is there any way to just delete the file? I've already changed the current model version to the one before it, and the app runs. However, when I right-click on the .xcdatamodel file in the Xcode file viewer, "Delete" is greyed-out. I also tried to remove the file from Finder, but it keeps the file in Xcode, redded-out.

Is there any way to fix this?

aopsfan
  • 2,451
  • 19
  • 30
  • 2
    I don't know, but I'm curious if anyone answers this. The only way I could find to do it was to manually edit the project file and remove it. – Jason Coco Dec 27 '11 at 21:07
  • Use git for all your projects. It is very easy to see exactly what changed and revert then. – trapper Feb 15 '17 at 05:18

2 Answers2

28

Yes - having done this a lot, to my knowledge the only way is to open up YourProject.xcodeproj/project.pbxproj in your favourite raw text editor (vim ftw!), and search for and remove both instances of the offending model file. Ie:

D6A5760112F22213004DEDCE /* MyModel.xcdatamodeld */ = {
  isa = XCVersionGroup;
  children = (
    D6EDB44614ED9D7E00C02938 /* MyModel-V12.xcdatamodel */,
    D6931E6214D78135007F0E03 /* MyModel-V11.xcdatamodel */,
    D61403DD14B7857100323E6D /* MyModel-V10.xcdatamodel */,
    D675476B149BD1F3007C160C /* MyModel-V9.xcdatamodel */,
    D6199DD5143DE428002869C1 /* MyModel-V8.xcdatamodel */,
  );
  currentVersion = D6EDB44614ED9D7E00C02938 /* MyModel-V12.xcdatamodel */;
  name = MyModel.xcdatamodeld;
  path = aPath/MyModel.xcdatamodeld;
  sourceTree = "<group>";
  versionGroupType = wrapper.xcdatamodel;
};

So in this case, I go hunting for the two instances of D6199DD5143DE428002869C1 and delete them both from the project file, and bang: Bob's my uncle. Also - you can reorder that chunk of children above in case you want the current one higher.

After I do that, I typically execute a manual source repo delete command on just the model-V8 dir too.

Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43
5

This can also be done removing the .xcdatamodeld from the project (just removing, not deleting). Then, in Finder (or Terminal) deleting the offending .xcdatamodel file. And finally, reimporting the .xcdatamodeld in the project.

FranMowinckel
  • 4,233
  • 1
  • 30
  • 26