Thursday, November 24, 2011

iOS UI Runtime Builder based on XML Definition

The basic idea behind this toolkit is to separate UI implementation from the source code. This idea comes from the beautiful Java toolkit SWIXML which was implemented for allowing separation on UI from business logic in Swing based applications. This toolkit is also implemented in Android SDK core for same reason and is much more used then hard coded UI. The concept mutates to new programming paradigm which is also known as declarative programming where we specify UI and we regardless of how it will be created we just want initialized elements to manipulate with.

With using tool that allows us to make separation on UI from the business logic we will have cleaner code which is much better for reading and maintaining than putting everything into the class.

In iOS you can make UI with setting all properties into the code for every view that we use or by using Interface Builder which generate some messy XML structure that is understood only by the Interface Builder itself, but in this case because everything is auto generated we can’t change anything into this XML. Application that is implemented with using Interface Builder has also slower compile time than the application that has UI implementation into the view controllers. For that reason toolkit that separate UI from the code and keeps the UI definition as simple XML file instead of complicated XIB is welcome.

iOS Runtime UI Builder parse the XML UI definition with using the fastest XML DOM parser TBXML, creates object structure for every XML Tag with its attributes and keeps that objects in memory which is very fast because we don’t depend on complicated XIBs that are also slower to parse then simple XML file. After parsing and creating object structure, for every encapsulated view we automatically make initialization on each view with setting attributes which were defined in the XML Tags. The objects that encapsulate the views are stored into the fast data structure allowing us fast lookup for the concrete object and set initialized view to the reference into the code. With using this toolkit we make the code cleaner because every property is automatically set with changing complicated methods with only several written attributes into the XML Tags for every view that we create in main view. If we have complex views with many wrapped views inside them it’s not a problem, all that views will be automatically add into the parent view which gives us freedom to experiment with different UI concepts easily.

Check it on Google Code