Infinite Loop —

iPhone dev: Convert XIB files to Objective-C

Ars looks at the open source nib2objc utility that lets you extract Objective- …

A handy open source utility by Adrian Kosmaczewski allows you to convert Interface Builder files to Objective-C code. With it, you can extract all the layout information and properties of your visual design and transform that into code. Nib2objc does exactly what its name suggests. With it, you can generate converted code that takes into account the class constructors, method calls, and more.

The utility is kind of like Code the Code's class-dump but for XIBs and NIBs instead of compiled code. It produces results that are obviously computer generated and yet usable at the same time. Here's a sample of the kind of code it generates:

As you can see, the emphasis is on creating correct and exhaustive detail. If you want the results to look pretty, you'll have to edit it by hand. The nib2objc utility exposes nearly all the information stored by and editable in Interface Builder. The sample above is the output for a simple UILabel instance.

Nib2objc has a few real limitations. According to the README at the git hub repository, it cannot produce values for UIImage, NSLocale or NSTimeZone instances. That's because the results are generated by the ibtool utility (/usr/bin/ibtool), which does not support them. It also cannot produce default property values. These limitations aside, it's a great tool for people who want to leverage IB's visual layout but want to expose object details inside their Xcode projects.

Nib2objc is hosted at github and issued under a general "Use this for good not evil" style of license.