24/7 twenty-four seven

iOS/OS X application programing topics.

XIBファイルをObjective-Cのソースコードに変換するツール

nib2objc

akosma/nib2objc · GitHub

以下のように、パラメータにXIBファイルを指定すると、標準出力にコードが出力されます。

$ nib2objc WebView.xib > WebView.m

このようなビューから下記のコードが出力されます。
XIBファイルをソースコードに変換する場合というのは、パフォーマンスのために、XIBファイルを使わないようにしたい場合がほとんどだと思うので、このコードをもってXIBファイルを置き換えるのは難しいです。
インスタンス変数やアクションの接続が無くなってしまうので、それらを再構築する手間を考えると、自分で書いた方が早いと思います。
ただ、ソースコードが公開されているので、工夫して改良すれば、便利なツールになりそうです。

UIBarButtonItem *view39 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
view39.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view39.enabled = YES;
view39.style = UIBarButtonItemStylePlain;
view39.tag = 0;
view39.width = 0.000;

UIBarButtonItem *view64 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
view64.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view64.enabled = YES;
view64.style = UIBarButtonItemStylePlain;
view64.tag = 0;
view64.width = 0.000;

UIBarButtonItem *view57 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
view57.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view57.enabled = YES;
view57.style = UIBarButtonItemStylePlain;
view57.tag = 0;
view57.width = 0.000;

UIBarButtonItem *view33 = [[UIBarButtonItem alloc] initWithTitle:(null) style:UIBarButtonItemStylePlain target:nil action:nil];
view33.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view33.enabled = YES;
view33.image = nil;
view33.style = UIBarButtonItemStylePlain;
view33.tag = 0;
view33.width = 0.000;

UIBarButtonItem *view66 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
view66.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view66.enabled = YES;
view66.style = UIBarButtonItemStylePlain;
view66.tag = 0;
view66.width = 0.000;

UIWebView *view31 = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)];
view31.frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
view31.alpha = 1.000;
view31.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view31.backgroundColor = [UIColor colorWithWhite:1.000 alpha:1.000];
view31.clearsContextBeforeDrawing = YES;
view31.clipsToBounds = YES;
view31.contentMode = UIViewContentModeScaleToFill;
view31.detectsPhoneNumbers = NO;
view31.hidden = NO;
view31.multipleTouchEnabled = YES;
view31.opaque = YES;
view31.scalesPageToFit = YES;
view31.tag = 0;
view31.userInteractionEnabled = YES;

UIBarButtonItem *view56 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:nil action:nil];
view56.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view56.enabled = YES;
view56.style = UIBarButtonItemStylePlain;
view56.tag = 0;
view56.width = 0.000;

UIBarButtonItem *view48 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
view48.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view48.enabled = YES;
view48.style = UIBarButtonItemStylePlain;
view48.tag = 0;
view48.width = 0.000;

UIToolbar *view32 = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 416.0, 320.0, 44.0)];
view32.frame = CGRectMake(0.0, 416.0, 320.0, 44.0);
view32.alpha = 1.000;
view32.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
view32.barStyle = UIBarStyleBlackTranslucent;
view32.clearsContextBeforeDrawing = NO;
view32.clipsToBounds = NO;
view32.contentMode = UIViewContentModeScaleToFill;
view32.hidden = NO;
view32.multipleTouchEnabled = NO;
view32.opaque = NO;
view32.tag = 0;
view32.userInteractionEnabled = YES;

UIBarButtonItem *view34 = [[UIBarButtonItem alloc] initWithTitle:(null) style:UIBarButtonItemStylePlain target:nil action:nil];
view34.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view34.enabled = YES;
view34.image = nil;
view34.style = UIBarButtonItemStylePlain;
view34.tag = 0;
view34.width = 0.000;

UIBarButtonItem *view36 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
view36.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view36.enabled = YES;
view36.style = UIBarButtonItemStylePlain;
view36.tag = 0;
view36.width = 0.000;

UIView *view27 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)];
view27.frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
view27.alpha = 1.000;
view27.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
view27.backgroundColor = [UIColor colorWithWhite:1.000 alpha:1.000];
view27.clearsContextBeforeDrawing = NO;
view27.clipsToBounds = NO;
view27.contentMode = UIViewContentModeScaleToFill;
view27.hidden = NO;
view27.multipleTouchEnabled = NO;
view27.opaque = YES;
view27.tag = 0;
view27.userInteractionEnabled = YES;

UIBarButtonItem *view38 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
view38.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view38.enabled = YES;
view38.style = UIBarButtonItemStylePlain;
view38.tag = 0;
view38.width = 0.000;

UIBarButtonItem *view35 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:nil];
view35.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
view35.enabled = YES;
view35.style = UIBarButtonItemStylePlain;
view35.tag = 0;
view35.width = 0.000;

[view27 addSubview:view31];
[view32 addSubview:view33];
[view32 addSubview:view34];
[view32 addSubview:view36];
[view32 addSubview:view38];
[view32 addSubview:view39];
[view32 addSubview:view48];
[view32 addSubview:view57];
[view32 addSubview:view35];
[view32 addSubview:view56];
[view32 addSubview:view64];
[view32 addSubview:view66];
[view27 addSubview:view32];