In one of my previous posts I explained how to create your own MainWindow.xib User Interface Document. I’ve now also created a screencast that guides you through the process. It is actually no longer necessary to use this. I personally think it is easier just to create your application from code, however it is useful to understand how an XCode 3 iOS application is constructed.

Where is MainWindow.xib in XCode 4 on youtube

Any feedback is appreciated in the comments (here, or on youtube).

kthxbye

In this article I want to give some advice as to which books will help you greatly in getting up to speed on iOS development. I browsed through many books while preparing the iOS development curriculum.

First things first: Objective-C

Book cover: Learning Objective-C 2.0 - Robert Clair

By far the best book I’ve seen is this one: Learning Objective-C 2.0 by Robert Clair. It covers in depth the programming language you will use to do iOS development. It contains many good and clear examples as well as exercises.

 

Book cover: Beginning iPhone 4 Development Exploring the iOS SDKThe next thing you will need to get your head around is the iOS SDK. I’ve used two books to learn this. The first book I recommend is Beginning iPhone 4 Development.  The book is built in tutorial form while explaining the concepts and introducing the SDK. The examples will bring you up to speed in a very hands-on way. You write lots and lots of code, and I think that is important to get to know the new environment. The book comes with sample code that you can run as well. The version I had used XCode3. That is a big disadvantage, you’ll still need to find your way around the IDE yourself.

Book cover: iOS 4 in ActionThe second book I recommend is iOS 4 in Action. This book is quite high-level, and gives you a good overview of the capabilities that exist. It is not very hands-on however. Some of the examples and sample code are somewhat superficial and only scratch the surface, but nonetheless it is a very pleasant read.

Another great resource to learn iOS development is the Stanford CS193P course on iTunesU. You can watch it for free, and the lector explains in detail, and at a good pace the ins and outs of iOS development. It is not the easiest resource, because it is mainly targeted at the Stanford college students, but once you have a good understanding of the basics, it will get you to a higher level of understanding.

The other kind of material you should be using all the time is the official apple documentation. The quality of the documentation is great, but it doesn’t replace the books. This is the real reference material that you need when discovering new and unfamiliar api’s. There are some User Guides that you should be reading.

If you don’t feel like spending too much time reading all these resource, following a training will certainly get you up to speed a lot faster. Seeing an instructor demo the programming language, environment and explaining how to get things done is just a very efficient way to learn.

Where to go next?

Book cover: Developing Enterprise iOS applicationsOnce you have a good understanding of the technologies and tools to build applications, the next step would be to consider the application development lifecycle and communicating to a back-end with REST+Json services and have a CMS in place to manage the back-end data as well.

Hope this helps.

[Update: I added a screencast of the process]

[Update: Interesting discussion of this post over on StackOverflow]

In the XCode 4.2 beta, MainWindow.xib is no longer included by default in some project templates. This means that you have to get your application to work by writing some code, using another method, or by manually reconstructing MainWindow.xib. This post shows the latter. Let’s get started.

Start with Empty Application template

If you create a new project in XCode 4.2 beta, and choose the Empty Application template to start from, change nothing and try running it in your iPhone 5.0 simulator, you will see an empty – black – screen. The only thing you get from the template is an xAppDelegate.h and .m.

We will now reconstruct our own MainWindow.xib, to get started with development the way you’re used to. So the next thing we do is add a New File to the project. Choose iOS > User Interface > Empty as template. Add Empty Interface Builder documentNext, choose iPhone, next give it the name MainWindow (.xib will be added automatically). By the way, the name of the file is not very important, but it’s nice to choose MainWindow, because that’s familiar.

Select the new File we just created. What we have now is an empty design surface, in what used to be Interface Builder. Here we’re going to change some things.

The empty design surface of MainWindow.xib

  • Change the class of File’s Owner to UIApplication

Change class of File's Owner to UIApplication

  • Find Object in the Library and drag it onto the Objects pane on the left.

Add Object to the document

  • Change the class of that Object to the xAppDelegate class that was created by the template, you might also want to clear out the “Object” label.

Change class of the object to xAppDelegate

  • Add a Window to the Objects pane on the left.

Add a window to the document

Now, let’s bind it all together. To do this, we first need to change some of the code in the xAppDelegate.h. We have to add IBOutlet to the window property it has, so that we can  hook it up in Interface Builder. The xAppDelegate.h should read something like this:

@interface DemoAppDelegate :
      UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) IBOutlet UIWindow *window;
@end

Don’t forget to save the file, otherwise Interface Builder will not be able to pick up the Outlet. Next we continue editing the MainWindow.xib

  • Control-Drag from the delegate outlet of the File Owner to the xAppDelegate object.

Link the application delegate

  • Control-Drag from the window outlet of the xAppDelegate to the Window.

Link the window outlet of the app delegate

  • Just for this demo, I’m adding a label to the window.

Add a label for testing

We’re not done yet, but we’re almost there.

  • Navigate to the project, and in the Summary tab, select MainWindow as the Main Interface.

Set the Main Interface to MainWindow

You can now run the project in the Simulator, and the window should show up. However there’s one last thing you might want to clean up. In xAppDelegate.m, there was actually code that creates a window as well. Just put the method

- (BOOL) application:didFinishLaunchingWithOptions:

in comment.

we're done

 

 

I hope this helps to understand exactly how an iOS app starts. The next thing you should do is add a ViewController, and push it onto the MainWindow. I’m not going to cover that here. Please leave your feedback in the comments.

kthxbye