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:

UILabel *view15 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 6.0, 272.0, 21.0)]; view15.frame = CGRectMake(20.0, 6.0, 272.0, 21.0); view15.adjustsFontSizeToFitWidth = YES; view15.alpha = 1.000; view15.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; view15.baselineAdjustment = UIBaselineAdjustmentAlignCenters; view15.clearsContextBeforeDrawing = YES; view15.clipsToBounds = YES; view15.contentMode = UIViewContentModeScaleToFill; view15.enabled = YES; view15.font = [UIFont fontWithName:@"Helvetica" size:17.000]; view15.hidden = YES; view15.lineBreakMode = UILineBreakModeTailTruncation; view15.minimumFontSize = 10.000; view15.multipleTouchEnabled = NO; view15.numberOfLines = 1; view15.opaque = NO; view15.shadowOffset = CGSizeMake(0.0, -1.0); view15.tag = 401; view15.text = @"Progress: "; view15.textAlignment = UITextAlignmentCenter; view15.textColor = [UIColor colorWithRed:0.000 green:0.000 blue:0.000 alpha:1.000]; view15.userInteractionEnabled = NO;

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.