2010-09-12

Convert NIB to XIB in Interface Builder and Xcode.

Why do this? It turns out NIB files don't play nicely with SCM. XIB contains the same information as NIB, but it works with SCM. This is because NIB files are "packages" to the OS and/or file system. XIB files are just XML.

This stuff was pointed out to me by the kind gentleman, Mark, at Stack Overflow.

More info about XIB files at Apple.

  1. Backup just in case. In Terminal:
    1. cd ~/Code/MyThing/English.lproj/
    2. cp -pr MainMenu.nib ~/tmp
  2. Make certain MyThing project is closed in Xcode. The auto-add-to-project feature will invoke later if Xcode has the project open, and I had trouble with that feature.
  3. In Interface Builder, File | Open Recent | MainMenu.nib - MyThing.
  4. File | Save As, choose File Type Interface Builder Cocoa Document (XIB 3.x). Don't save it under ~/Code/MyThing/English.lproj, but up one level in ~/Code/MyThing.
  5. You'll probably see the "foreign files" warning dialog telling you, "file .svn will not be preserved". Who cares. Press Save button.
  6. Open Xcode.
  7. In Xcode, left pane, CTRL-Click MainMenu.nib, Delete. Press Also Move to Trash button.
  8. In left pane, CTRL-Click MyThing at top, Add | Existing Files... Choose ~/Code/MyThing/MainMenu.xib. Do not add to any targets. Other defaults in dialog box should be OK.
  9. After dialog, back in left pane, CTRL-Click MainMenu.xib, Get Info.
  10. In File "MainMenu.xib" Info dialog, General tab, change File Type to file.xib. Close dialog.
  11. Drag MainMenu.xib into Compile Sources folder of your targets.
  12. Build | Clean All Targets, followed by Build | Build, and then press the Run button in the tool bar.
  13. Your application should be running like it was before with the NIB file as a resource, but now it is compiling the XIB into a NIB during build instead.
  14. In Xcode, left pane, under SCM twisty, CTRL-click MainMenu.xib, Add to Repository.
Unresolved problem

When I double-click MainMenu.xib in Xcode, it opens the file in a text editor (since it is XML). In order to open it in Interface Builder, I have to CTRL-click and Open in Finder. Annoying.

2 comments:

  1. is there a program to convert without IB...I installed XCode 4 and my old NIB files do not work at all because of the missing IB support files. Or does Apple force yo to do something stupid like reinstall XCode 3, convert all your NIBs and reinstall XCode 4?

    ReplyDelete
  2. Bravo! Thank you for documenting this. It had eluded me completely and I'll be darned if I can find any reference in Apple's docs on how to do this. The fact that they deprecated and removed, seemingly, any documentation on IB in Xcode 3 – not a good move – may be a part of the reason. Thank you!

    ReplyDelete