What are XIB files?


http://speirs.org/blog/2007/12/5/what-are-xib-files.html

What are XIB files?


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  .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.

December 6, 2007 |  Unregistered CommenterJon Hess

Bloody good post, IMHO.

That's about all I have to say on the subject :)

December 6, 2007 |  Unregistered CommenterMo

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

December 8, 2007 |  Unregistered CommenterKelan

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.

December 10, 2007 |  Unregistered CommenterJames

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).

December 10, 2007 |  Unregistered Commenterfraserspeirs

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

December 10, 2007 |  Unregistered CommenterJames

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/

December 13, 2007 |  Unregistered CommenterNick

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?

December 19, 2009 |  Unregistered CommentergreggT

XIBs add more complexity to the code and I prefer building applications without them

February 18, 2010 |  Unregistered CommenterGaish Prasad

Thank you Buck diamond Pensacola cascade stenopterygius polychrome peppercorn scour,cite fiftieth Hamamelidae bola alertness cheap ugg boots usefulness Antonius Esselen

November 25, 2010 |  Unregistered Commentercheap ugg boots
December 24, 2010 |  Unregistered Commentercheap 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.

December 27, 2010 |  Unregistered Commenterfake designer handbags

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

January 18, 2011 |  Unregistered Commentercool grey 11 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/

February 13, 2011 |  Unregistered Commentergkoreman

cheapsale

March 12, 2011 |  Unregistered Commentercoach bag

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

March 21, 2011 |  Unregistered Commentercoach 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

March 31, 2011 |  Unregistered Commenterdiscount handbags

china electronics from http://www.buybuyseller.com/

April 3, 2011 |  Unregistered Commentercheap electronics

That probably means it's a dumb question, so apologies in advance.
club penguin cheats

April 20, 2011 |  Unregistered CommenterMary

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

May 5, 2011 |  Unregistered Commentercheap handbags

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.

May 7, 2011 |  Unregistered CommenterCoach Outlet

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!

May 10, 2011 |  Unregistered Commenterdesigner handbags outlet

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!

May 10, 2011 |  Unregistered Commenterchi flat iron

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

May 19, 2011 |  Unregistered Commentercheap handbags

This is a great post. you got cheap shoes online .I like cheap designer shoes as well give you designer shoes outlet

May 21, 2011 |  Unregistered Commentercheap shoes online
Editor Permission Required
You must have editing permission for this entry in order to post comments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值