Sunday, May 16, 2010

Iphone Application startup: the complexity behind the scenes.

Let' write an IPhone application which displays a single "Helloworld" label at the center of the display.
It's plenty of tutorials and books which explain how to do that: usually they explain how to use a View Based project template in X-Code, add a label with Interface Builder, and run the application.
Very easy.
But have a look to the set of files generated by Xcode while choosing the View based template: you will see a main method, an Application Delegate class, a ViewController class, a plist file, and two .xib files which define the main Window and the main View of the application.
Also, you will notice that the main .xib file is referenced in the plist file (as the "main nib" ..), and that it is made up of five objects: a UIApplication, a UI Responder, the Application Delegate, the View Controller and a Window Object. Also, some references between objects (or, more precisely "Outlets") are defined: the UIApplication contains a reference to the Delegate Object, which in turn contains references to both the ViewController and the Main window. Finally the ViewController is owner of the second .xib file, which defines the actual interface of our application and is connected to our ViewController class by the usual mechanism of Outlets and Actions.
Quite complicated for a simple HelloWorld application!

Fortunately, somebody (Bill Dudney) already made an effort to put all the pieces together and explain very clearly how they all work together: Demystifying iPhone App Startup
Really a great post, highly recommended!

No comments:

Post a Comment