Quick Tip: Going completely XIB-less
In some of my tutorials on MobileTuts+ I go through explaining XIB-less development and how to make your interfaces sans Interface Builder. What I demonstrated was 99% XIB-less and there was one main XIB left, the MainWindow.xib.
At the time I was unaware of a nice method of removing this XIB. However, after reading through some posts there is an easy way to get rid of that last XIB.
Step 1: Info.plist change
Open up the PROJECT_NAME-Info.plist in your project. Locate the āMain nib file base nameā row in the dictionary and give it a good āol delete. Save the file.
Step 2: Changing main.m
Next, if you are already 99% XIB-less then go ahead now and delete MainWindow.xib. If you have view controllers setup in MainWindow.xib then you will need to move them to the Application Delegate file. See Beginning iOS Development video #3 on Interface Builder for more information on how to do this, seek to 30:00 in the video and after that then delete the MainWindow.xib.
Open the main.m (in Other Sources) file in your project and find the code shown below:
And here is the code after the change:
So lets have a look at the difference. On line 6 in the code we have the UIApplicationMain method which if we look at in the documentation says:
This function is called in the main entry point to create the application object and the application delegate and set up the event cycle.
It accepts 4 arguments. The first 2 are passing the arguments through from the main() method. The last 2 allow you to specify the āprincipal class nameā and the ādelegate class nameā. The principal class name is the name of the class that the Application Delegate inherits from, in this case its UIApplication. Finally, the delegate class name is the name of the class that we create so the Lap Timer applicationās Application Delegate is called āLapTimerAppDelegateā.
Once the change is made in main.m, as illustrated above, then its time to move to the last step.
Step 3: Creating the window in code
Since the MainWindow.xib file is no longer available we have to create the window used throughout the application. To do this itās a simple 1 line addition to our Application Delegate.
At the top of the main application initialisation call in the Application Delegate the window is allocated and initialised. The windowās frame is set as the bounds of the current deviceās main screen.
Check your Application Delegates header file and make sure the UIWindow property is no longer an IBOutlet.
Thats it! No more XIBās!












