The Xcode tools in Leopard introduced a new file format for user interfaces. In the brach of the prehistory of Mac OS X that includes NeXT, interfaces were defined in files known as NIBs, from their .nib extension.
A NIB file is a Mac OS X package containing, usually, a keyedobjects.nib file and a classes.nib file. When building an application, these files are copied into the app's bundle and are loaded at runtime to provide the user interface for the application. For what comes next, bear in mind that the NIB in your Xcode project is the same NIB that is loaded at runtime in the application.
Interface Builder 3 on Leopard introduces a new file format: XIB. The developer experience of editing XIB files in Interface Builder is identical to editing a NIB file but, in many other ways a XIB is radically different from a NIB file. If I had one criticism of WWDC '07, it was that they didn't spend enough time explaining XIBs and their implications.
File Format
Firstly, the XIB file format is completely different from that of a NIB. A XIB is not a package - it is a single self-contained XML file. The XML schema is specific to XIBs - it is not a simple XML Property List.
This brings a couple of advantages. Firstly, it's a benefit for users of tools that are not package-aware. In early days, Interface Builder would blow away the
Secondly, the file format is vaguely human-understandable. It is very dense and not entirely obvious, but one can make some sense of it. This helps in some of those last-ditch situations where you're grepping the file to find out where a particular binding is referenced.
It is worth pointing out two things that this text-based file format does not immediately deliver: hand-editability and mergability. The XIB file is an XML representation of an object graph and, as such, it is considered dangerous to edit it by hand. Merging is just a machine-assisted form of hand editing and is likely problematic. However, the text format might assist in understanding where the conflicts lie.
Working with XIBs
The primary tool for editing XIB files is, of course, Interface Builder. For many years, there has been a command line tool for manipulating nibs called
The man page for ibtool contains a lot of detail, but it's worth noting a couple of new capabilities: the
There are also many options in
Deploying XIBs
The crucial difference between XIB and NIB for deployment is that a XIB is not a deployable file. Xcode 3 will compile a XIB into a deployable NIB when the project is built and will include that deployable NIB in the finished application.
If you're using XIB in your Xcode projects, you might see a CompileXIB build operation going past. What's actually happening there is that Xcode is calling:
It's
The NIB file produced by compiling a XIB file in
XIB Wishlist
Interface Builder 3, XIBs, and the new capabilities of
The one remaining thing I really want to see in this tool set is the ability to diff and ultimately merge XIB files, but I would be very happy to just get diff capabilities right now. It doesn't even need to be graphical - just a text report would be great. It seems that the XIB file format lays the foundation for something like that to happen in the future. Let's hope we get there.
Further Reading
There's not a huge amount about XIBs in there, but the Interface Builder 3.0 Release Notes are worth reading.
[ Update: Jens Ayton pointed out that I had, incorrectly, used the term 'bundle' in a number of places to refer to NIB files which are, in fact, packages.]
A NIB file is a Mac OS X package containing, usually, a keyedobjects.nib file and a classes.nib file. When building an application, these files are copied into the app's bundle and are loaded at runtime to provide the user interface for the application. For what comes next, bear in mind that the NIB in your Xcode project is the same NIB that is loaded at runtime in the application.
Interface Builder 3 on Leopard introduces a new file format: XIB. The developer experience of editing XIB files in Interface Builder is identical to editing a NIB file but, in many other ways a XIB is radically different from a NIB file. If I had one criticism of WWDC '07, it was that they didn't spend enough time explaining XIBs and their implications.
File Format
Firstly, the XIB file format is completely different from that of a NIB. A XIB is not a package - it is a single self-contained XML file. The XML schema is specific to XIBs - it is not a simple XML Property List.
This brings a couple of advantages. Firstly, it's a benefit for users of tools that are not package-aware. In early days, Interface Builder would blow away the
.svn
directory inside the NIB package. That hasn't been a problem for years, but other tools may still have issues.
Secondly, the file format is vaguely human-understandable. It is very dense and not entirely obvious, but one can make some sense of it. This helps in some of those last-ditch situations where you're grepping the file to find out where a particular binding is referenced.
It is worth pointing out two things that this text-based file format does not immediately deliver: hand-editability and mergability. The XIB file is an XML representation of an object graph and, as such, it is considered dangerous to edit it by hand. Merging is just a machine-assisted form of hand editing and is likely problematic. However, the text format might assist in understanding where the conflicts lie.
Working with XIBs
The primary tool for editing XIB files is, of course, Interface Builder. For many years, there has been a command line tool for manipulating nibs called
nibtool
. In Leopard,
nibtool
has been renamed (or replaced - I'm not sure) by
ibtool
and has acquired many new tricks.
The man page for ibtool contains a lot of detail, but it's worth noting a couple of new capabilities: the
--convert
option will rename old classes to new. Presumably it is
ibtool --convert
that allows Xcode 3.0's refactoring tools to reach into interface files.
There are also many options in
ibtool
for printing the details of a NIB or XIB to an XML Property List, including
--objects
,
--connections
,
--hierarchy
and
--classes
, although a mode to conveniently list the bindings in an interface sadly isn't available.
Deploying XIBs
The crucial difference between XIB and NIB for deployment is that a XIB is not a deployable file. Xcode 3 will compile a XIB into a deployable NIB when the project is built and will include that deployable NIB in the finished application.
If you're using XIB in your Xcode projects, you might see a CompileXIB build operation going past. What's actually happening there is that Xcode is calling:
ibtool --errors --warnings --notices --output-format human-readable-text --compile your.xib output.nib
It's
ibtool
that compiles XIB to NIB, not Xcode itself, and it emits useful warnings and errors about your XIB files right in the Xcode build window. I've found this to be very, very valuable when working with my XIB-based projects.
The NIB file produced by compiling a XIB file in
ibtool
is a deployment-only file. Unlike most earlier NIB files, one cannot extract a deployment NIB file from an application and open it in Interface Builder for inspection. This is slightly sad, since it makes it harder to learn how others did things. However, in recent years, it has rarely been a worthwhile learning experience to open deployed NIBs, since all one usually finds is a morass of "Custom View" panels.
XIB Wishlist
Interface Builder 3, XIBs, and the new capabilities of
ibtool
are a great leap forward in Mac development. I've been using XIB files exclusively in my Leopard-only development. I haven't yet converted FlickrExport to be XIB-based. They work perfectly for me, but I have heard of the occasional problem with opening a XIB-compiled NIB on Tiger, so I'm not sure that I'll adopt XIB files in code that has to be Tiger-compatible.
The one remaining thing I really want to see in this tool set is the ability to diff and ultimately merge XIB files, but I would be very happy to just get diff capabilities right now. It doesn't even need to be graphical - just a text report would be great. It seems that the XIB file format lays the foundation for something like that to happen in the future. Let's hope we get there.
Further Reading
There's not a huge amount about XIBs in there, but the Interface Builder 3.0 Release Notes are worth reading.
[ Update: Jens Ayton pointed out that I had, incorrectly, used the term 'bundle' in a number of places to refer to NIB files which are, in fact, packages.]
Reader Comments (74)
Great article. While doing a straight text diff of XIB files is currently daunting, you may find it useful to pipe XIB's through "ibtool --objects --connections file.xib" and then diff the results.
Bloody good post, IMHO.
That's about all I have to say on the subject :)
Thanks for this post. A quick note is that it looks like the final 2 arguments for your ibtool compile command should actually be reversed, so it becomes:
ibtool --errors --warnings --notices --output-format human-readable-text --compile output.nib MainMenu.xib
Hi Frasier,
Forgive me if this is a dumb question, but I'm new to Xcode and Cocoa.
How do I use xib files? The documentation simply says to save the nib as a xib. It doesn't say anything else, so apart from the fact that the xib file is on disk, I can't find any other reference to it in my Xcode project, nor find any way of adding it to my project.
Do I have to add it? Do I have to remove the existing nib file? Does 'Saving As..." make it active by default?
I've searched far and wide through both the documentation and the internet and cannot find any answer to the question of how to use a xib file. That probably means it's a dumb question, so apologies in advance. Help gratefully appreciated.
James,
Yes, the default Xcode templates all use NIBs rather than XIBs. To convert a NIB to a XIB, you would:
- Open the NIB
- Choose File / Save As...
- From the File Type menu choose the one that ends in "(XIB 3.x)"
At this point, you'll have a .nib file and a .xib file. You can just delete the .nib file and drag the XIB file into the XCode project at the same place that the NIB was. You'll need to delete the reference to the NIB file from your project too (select it and press backspace).
Fraser,
Thanks so much for your quick reply.
Incidentally, I keep running into great stuff by you - interviews etc. Thanks so much for those. Not only are you one of the main sources of good information, but what you say is always clean and clear.
Best regards and thanks!
James
Did you mean "branch", Fraser? You've got "brach" ... or is it some Scots term I don't know? :-)
"A NIB file is a Mac OS X bundle containing, usually, a keyedobjects.nib file and a classes.nib file. When building an application, these files are copied into the app’s bundle and are loaded at runtime to provide the user interface for the application."
Don't nibs have a third file, info.nib as well? Also, AFAIK, not all these are loaded at runtime. Apple says:
"These are wrappers, ending in .nib that contain three files: classes.nib, info.nib, and keyedobjects.nib. These files can be opened for development with any version of Interface Builder. Only the keyedobjects.nib file is required at runtime, and these files are deployable on any recent Mac OS X version."
http://developer.apple.com/releasenotes/DeveloperTools/RN-InterfaceBuilder/
so does anyone know how large teams merge conflicting NIB/XIB files when the versioning system cannot merge them? for example, does a human have to understand all those unique ids?
XIBs add more complexity to the code and I prefer building applications without them
Thank you Buck diamond Pensacola cascade stenopterygius polychrome peppercorn scour,cite fiftieth Hamamelidae bola alertness cheap ugg boots usefulness Antonius Esselen
cheap ugg online
If you are looking to get the
fake designer handbags at a much cheaper price then it is better to go with the http://www.excelhandbag.com. The quality of the replica handbags paypal is maintained to high standards such that they last for a long time as the original handbags. There will not be a single difference between the original one and the replica handbag.Here you can find not only quality but also the latest updated designs that will fit to your taste. You can find the perfect handbag to your taste with the http://www.excelhandbag.com.
jordan true flight
retro jordans
air jordan retro 10
Nike Air Max 2010
cheap Jordan Spizike for sale
air jordans for girls
100 authentic air jordans
kids jordan shoes
air force shoes
jordan release dates
Nike Air Jordan Retro XI
Air Jordan 6(VI)
air jordan 6 infrared pack 2010
jordan 1
buy jordan shoes
jordan 12
jordan 5
authentic air jordans for sale
If you want to avoid the complexity of XIBs, you can create your iOS apps without a XIB. I describe how to do this on my blog.
http://gkoreman.com/blog/2011/02/13/programmatic-ios-user-interface/
cheapsale
Thanks for your opinion. we sell discount handbags I totally like with it.I like cheap designer handbags as well and someone is looking for coach handbags online? People usually preferwholesale Gucci handbags, especially when they visit some prada handbags outlet. In some areas,people like to wholesale LV handbags. They will find some store doing very cheap or discounted handbags outlet. Certainly, is a good way to earn money.
fendi handbags wholesale
Thanks for your opinion. discount handbags I totally like with it.I like cheap designer handbags as well and someone is looking for new era caps? People usually prefer cheap handbags online, especially when they visit some clothing store. In some areas,people like to wholesale clothing. They will find some store doing very cheap or discounted handbags outlet. Certainly, is a good way to earn money.
designer handbags outlet
china electronics from http://www.buybuyseller.com/
That probably means it's a dumb question, so apologies in advance.
club penguin cheats
A great post but How to select a cool handbags. we sell cheap handbags We are the best store provided various cheap designer handbags but only a little white to make coach handbags online
Latest Coach Purses Outlet and Coach tote bags can be purchased at discounted rates from aCoach Handbags online store.We Offering a ambit of comfortable coach purse accessories, it showcases adulthood in a different way.The fine materials and trendy designs of coach sale, they normally are somewhat expensive.
Yesterday, my friend bought a designer handbags outlet which is so beautiful, i am surprised by the design and style. Do you have designer handbags outlet now? if not, go to online store and have one, it is so amazing!!! There are many online stores having designer handbags outlet, i believe you gonna like it!
Yesterday, my friend bought a chi flat iron which is so beautiful, i am surprised by the design and style. Do you have chi flat iron now? if not, go to online store and have one, it is so amazing!!! There are many online stores having chi flat iron, i believe you gonna like it!
A great post but How to select a cool handbags. we sell cheap handbags We are the best store provided various cheap designer handbags but only a little white to make coach handbags online
This is a great post. you got cheap shoes online .I like cheap designer shoes as well give you designer shoes outlet