开发者

Convert Interface Builder code to Xcode

Is it true that everything you do in Interface Builder can be done programmatically? If your project uses Interface Builder to make the GUI, ca开发者_运维技巧n that code be converted to native Xcode and inserted into the project?


It is true that anything you can do in Interface Builder you can do programatically. However, IB does not generate code, so there is not really anything to 'convert' to source code for your project.


Interface Builder creates archived objects -- serialized instances of class instances -- and works directly from those. While you can reuse your .xib files (which some people still insist on calling "nibs") in any number of projects, you should note that:

  1. Your nib is already code: it's just very verbose and hard-to-read XML. This XML contains the serialized (say "archived") instances.
  2. You cannot "convert" your xib to Objective-C code, or at least Xcode does not provide a way to do this (and I don't know who would).
  3. If you do not have the classes that the xib expects, you will run into errors using your xib.


I wrote a utility to convert .xib files to code. It's still experimental, but should do the majority of the grunt work converting to code:

https://github.com/Raizlabs/Eject

You can try it out online:

https://eject.herokuapp.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜