public
Description: Command-line utility to transform NIB files for the iPhone into Objective-C code files
Homepage: http://arstechnica.com/apple/guides/2009/04/iphone-dev-convert-xib-files-to-objective-c.ars
Clone URL: git://github.com/akosma/nib2objc.git
Click here to lend your support to: nib2objc and make a donation at www.pledgie.com !
name age message
file .gitignore Fri Mar 13 09:12:41 -0700 2009 First commit; the NSTask is setup and a NSDicti... [Adrian Kosmaczewski]
directory Categories/ Tue Mar 17 08:30:37 -0700 2009 Added support for UITabBar and UITabBarItem ins... [Adrian Kosmaczewski]
file LICENSE Mon Mar 16 03:22:01 -0700 2009 Added a license file [Adrian Kosmaczewski]
file NibProcessor.h Tue Mar 17 08:10:22 -0700 2009 Removed copyright information [Adrian Kosmaczewski]
file NibProcessor.m Tue Mar 17 08:10:22 -0700 2009 Removed copyright information [Adrian Kosmaczewski]
directory Processors/ Tue Mar 17 08:30:37 -0700 2009 Added support for UITabBar and UITabBarItem ins... [Adrian Kosmaczewski]
file README.textile Tue Mar 17 06:04:47 -0700 2009 Updated the readme file [Adrian Kosmaczewski]
file TestViewController.xib Tue Mar 17 08:30:37 -0700 2009 Added support for UITabBar and UITabBarItem ins... [Adrian Kosmaczewski]
file nib2objc.m Sat Mar 14 03:53:42 -0700 2009 Added a UIControl-related processor; renamed th... [Adrian Kosmaczewski]
directory nib2objc.xcodeproj/ Tue Mar 17 08:30:37 -0700 2009 Added support for UITabBar and UITabBarItem ins... [Adrian Kosmaczewski]
file nib2objc_Prefix.pch Fri Mar 13 09:12:41 -0700 2009 First commit; the NSTask is setup and a NSDicti... [Adrian Kosmaczewski]
file sample.m Tue Mar 17 08:29:49 -0700 2009 New run of the sample.sh script [Adrian Kosmaczewski]
file sample.sh Mon Mar 16 03:48:48 -0700 2009 Added a sample script to show how to use the to... [Adrian Kosmaczewski]
README.textile

nib2objc – NIB to Objective-C converter

This utility converts NIB files (or XIB ones) into Objective-C code, including all the properties of each instance, the documented constructor calls, and also the view hierarchy. It uses the output of the ibtool utility bundled with the Xcode tools. For more information about ibtool, please check the ibtool man page.

Usage

Compile and put the utility in your path, and then call

nib2objc yourfile.xib > code.m

This will generate a file with the output of the conversion, similar to this (check out the included sample.m file for the full version):

    // ...
    UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)];
    view6.frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
    view6.alpha = 1.000;
    view6.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    view6.backgroundColor = [UIColor colorWithWhite:0.750 alpha:1.000];
    view6.clearsContextBeforeDrawing = NO;
    // ...

    UIButton *view9 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    view9.frame = CGRectMake(167.0, 65.0, 72.0, 37.0);
    view9.adjustsImageWhenDisabled = YES;
    view9.adjustsImageWhenHighlighted = YES;
    view9.alpha = 1.000;
    view9.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
    view9.clearsContextBeforeDrawing = NO;
    view9.clipsToBounds = NO;
    view9.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    // ...
    [view9 setTitleShadowColor:[UIColor colorWithWhite:0.000 alpha:1.000] forState:UIControlStateSelected];

    // ...
    [view6 addSubview:view9];
    // ...

The generated code takes into account the real class hierarchies in the UIKit, and it outputs the correct constructors and/or method calls for each object, depending on its class, including the enum values corresponding to the properties using them.

Limitations

  • For the moment this utility only works for UIKit views (iPhone), but it should be easy to extend to those of the AppKit too.
  • It cannot output the values of UIImage, NSLocale or NSTimeZone properties, because ibtool does not support them.
  • It does not distinguishes default values for properties, and as such, it outputs all the information it can find about a particular instance.