Xcode 5: How to revert to an old version of a XIB
I have 'legacy code'. It has been a few years since an app I wrote first debuted on the App Store, but it all still works. With iOS 7, I decided to sprinkle in some AutoLayout to bring some parts of the app into the modern era, but ran into some problems and decided after a few commits that I wanted to back out. I decided to roll the XIB back to it's original pre-iOS 7 self. Except when I tried to open it, I got this really odd error:
The document <xib name> could not be opened. Could not determine the type of data.
At this point Xcode can't determine what kind of document it is, for some reason, and just gives up. I scoured the Internet for a half-hour before it donned on me: Xcode 5 makes updates old XIBs to a new XML structure when they are opened to make them more stream-lined and easier to diff, like storyboards. In order to rollback to the old version it takes a few steps:
- DO NOT revert your code first.
- Go into the document inspector in Interface Builder and change the "Opens in" attribute to "Xcode 4.6"
- Accept the warning that you'll lose iOS 7 capability.
- Roll back the changes in git.
- Change the "Opens in" attribute back to "Default (5.0)".
- Presto-chango: you have now rolled back to the old revision of your XIB and it's now in the new Xcode 5 format.
- Commit and push (you don't want to have to do this again, do you?)
I suspect what is happening is that Xcode attempted to parse the old format, thinking it was in the new format, and then gets discombobulated. Interesting bug and a use case that does not appear to be in a unit test. :)