Convert the XIB file into objective-C code

Source: Internet
Author: User

How can I convert an XIB file to an object-C source code?

You can use nib2objc to download the source code of this tool from https://github.com/akosma/nib2objc.

The downloaded project code is compiled with xcode to generate a command line program file.Nib2objc. Run the following command to start the conversion.

Nib2objc 1.xib> 1.m

If the content of 1.xib is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Archive type = "com. Apple. interfacebuilder3.cocoatouch. XIB" version = "7.10">
<DATA>
<Int key = "ibdocument. systemtarget"> 800 </int>
<String key = "ibdocument. systemversion"> 10c540 </string>
<String key = "ibdocument. interfacebuilderversion"> 759 </string>
<String key = "ibdocument. appkitversion"> 1038.25 </string>
<String key = "ibdocument. hitoolboxversion"> 458.00 </string>
<Object class = "nsmutabledictionary" Key = "ibdocument. pluginversions">
<String key = "ns. key.0"> com. Apple. interfacebuilder. ibcocoatouchplugin </string>
<String key = "ns. object.0"> 77 </string>
</Object>
<Object class = "nsmutablearray" Key = "ibdocument. editedobjectids">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Integer value = "6"/>
</Object>
<Object class = "nsarray" Key = "ibdocument. plugindependencies">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<String> com. Apple. interfacebuilder. ibcocoatouchplugin </string>
</Object>
<Object class = "nsmutabledictionary" Key = "ibdocument. Metadata">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Object class = "nsarray" Key = "dict. sortedkeys" id = "0">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
</Object>
<Object class = "nsmutablearray" Key = "dict. Values">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
</Object>
</Object>
<Object class = "nsmutablearray" Key = "ibdocument. rootobjects" id = "1000">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Object class = "ibproxyobject" id = "372490531">
<String key = "ibproxiedobjectidentifier"> ibfilesowner </string>
<String key = "targetruntimeidentifier"> ibcocoatouchframework </string>
</Object>
<Object class = "ibproxyobject" id = "843779117">
<String key = "ibproxiedobjectidentifier"> ibfirstresponder </string>
<String key = "targetruntimeidentifier"> ibcocoatouchframework </string>
</Object>
<Object class = "ibuiview" id = "774585933">
<Reference Key = "nsnextresponder"/>
<Int key = "nsvflags"> 274 </int>
<String key = "nsframesize"> {320,460} </string>
<Reference Key = "nssuperview"/>
<Object class = "nscolor" Key = "ibuibackgroundcolor">
<Int key = "nscolorspace"> 3 </int>
<Bytes key = "nswhite"> mc43nqa </bytes>
<Object class = "nscolorspace" Key = "nscustomcolorspace">
<Int key = "nsid"> 2 </int>
</Object>
</Object>
<Bool key = "ibuiclearscontextbeforedrawing"> NO </bool>
<Object class = "ibuisimulatedstatusbarmetrics" Key = "ibuisimulatedstatusbarmetrics"/>
<String key = "targetruntimeidentifier"> ibcocoatouchframework </string>
</Object>
</Object>
<Object class = "ibobjectcontainer" Key = "ibdocument. Objects">
<Object class = "nsmutablearray" Key = "connectionrecords">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Object class = "ibconnectionrecord">
<Object class = "ibcocoatouchoutletconnection" Key = "connection">
<String key = "label"> View </string>
<Reference Key = "Source" ref = "372490531"/>
<Reference Key = "destination" ref = "774585933"/>
</Object>
<Int key = "connectionid"> 7 </int>
</Object>
</Object>
<Object class = "ibmutableorderedset" Key = "objectrecords">
<Object class = "nsarray" Key = "orderedobjects">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Object class = "ibobjectrecord">
<Int key = "objectid"> 0 </int>
<Reference Key = "object" ref = "0"/>
<Reference Key = "children" ref = "1000"/>
<Nil key = "parent"/>
</Object>
<Object class = "ibobjectrecord">
<Int key = "objectid">-1 </int>
<Reference Key = "object" ref = "372490531"/>
<Reference Key = "parent" ref = "0"/>
<String key = "objectname"> file's owner </string>
</Object>
<Object class = "ibobjectrecord">
<Int key = "objectid">-2 </int>
<Reference Key = "object" ref = "843779117"/>
<Reference Key = "parent" ref = "0"/>
</Object>
<Object class = "ibobjectrecord">
<Int key = "objectid"> 6 </int>
<Reference Key = "object" ref = "774585933"/>
<Reference Key = "parent" ref = "0"/>
</Object>
</Object>
</Object>
<Object class = "nsmutabledictionary" Key = "flattenedproperties">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Object class = "nsarray" Key = "dict. sortedkeys">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<String>-1. customclassname </string>
<String>-2. customclassname </string>
<String> 6. ibeditorwindowlastcontentrect </string>
<String> 6. ibplugindependency </string>
</Object>
<Object class = "nsmutablearray" Key = "dict. Values">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<String> untitledviewcontroller </string>
<String> uiresponder </string>
<String> {239,654 },{ 320,480 }}</string>
<String> com. Apple. interfacebuilder. ibcocoatouchplugin </string>
</Object>
</Object>
<Object class = "nsmutabledictionary" Key = "unlocalizedproperties">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Reference Key = "dict. sortedkeys" ref = "0"/>
<Object class = "nsmutablearray" Key = "dict. Values">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
</Object>
</Object>
<Nil key = "activelocalization"/>
<Object class = "nsmutabledictionary" Key = "localizations">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Reference Key = "dict. sortedkeys" ref = "0"/>
<Object class = "nsmutablearray" Key = "dict. Values">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
</Object>
</Object>
<Nil key = "sourceid"/>
<Int key = "maxid"> 7 </int>
</Object>
<Object class = "ibclassdescriber" Key = "ibdocument. Classes">
<Object class = "nsmutablearray" Key = "referencedpartialclassdescriptions">
<Bool key = "encodedwithxmlcoder"> Yes </bool>
<Object class = "ibpartialclassdescription">
<String key = "classname"> untitledviewcontroller </string>
<String key = "superclassname"> uiviewcontroller </string>
<Object class = "ibclassdescriptionsource" Key = "sourceidentifier">
<String key = "majorkey"> ibprojectsource </string>
<String key = "minorkey"> classes/untitledviewcontroller. H </string>
</Object>
</Object>
</Object>
</Object>
<Int key = "ibdocument. localizationmode"> 0 </int>
<String key = "ibdocument. targetruntimeidentifier"> ibcocoatouchframework </string>
<Object class = "nsmutabledictionary" Key = "ibdocument. plugindeclareddevelopmentdependencies">
<String key = "ns. key.0"> com. Apple. interfacebuilder. cocoatouchplugin. interfacebuilder3 </string>
<Integer value = "3100" Key = "ns. object.0"/>
</Object>
<Bool key = "ibdocument. plugindeclareddependenciestracksystemtargetversion"> Yes </bool>
<String key = "ibdocument. lastknownrelativeprojectpath"> untitled. xcodeproj </string>
<Int key = "ibdocument. defaultpropertyaccesscontrol"> 3 </int>
<String key = "ibcocoatouchpluginversion"> 77 </string>
<Nil key = "ibcocoatouchsimulationtargetruntimeidentifier"/>
</Data>
</Archive> the source code after the conversion is executed is as follows: 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;
View6.clipstobounds = no;
View6.contentmode = uiviewcontentmodescaletofill;
View6.hidden = no;
View6.multipletouchenabled = no;
View6.opaque = yes;
View6.tag = 0;
View6.userinteractionenabled = yes; according to the test results, only view (including the subclass of uiview) related items can be converted, and the contact between the control and its corresponding event is lost. The converted attributes will generate the corresponding objective-C code, whether or not the attribute value is the default.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.