{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Source Code of First iPhone Application Explained
Summary
This article explains the code of a simple first iPhone application. The class diagram and overall structure of the code is discussed here. Application Delegate and View Controller classes are also introduced.
 
Table of Contents

Creation of the first iPhone application

The Source Code Files

Figure 1. The source code files that you would change in this project. You would change the app delegate and controller class source files directly. The user interface files are manipulated via Interface Builder.

main

App Delegate

View Controller

The Class Model Diagram

Figure 2. The Class Diagram for the iPhone application named FirstApp. Here the custom classes point towards built-in classes and a protocol. The application delegate implements UIApplicationDelegate protocol and the main view is based on UITableViewController.

Explanation for the Source Code

 
Article Series
Previous Article:
Test Your Knowledge: Debugging Fundamentals of an iPhone application explained
This article is part of the Series:
Article Series: Getting started with iPhone development
Next Article:
Test Your Knowledge: Source Code of First iPhone Application Explained

Creation of the first iPhone application

The first iPhone application discussed in this article has been created in the following article:

Creation of First iPhone application explained

This project is a simple navigation-based application. It uses a table view on the main window. From the code side, a table view controller (UITableViewController) is used to provide the functionality for a table based view.

The article below explains the actual source files for the above project. Links to the detailed articles on each source piece (main method and classes) are also provided.

The Source Code Files

For this project, we see three sets of source code files:

  • main
  • App Delegate
  • View Controller

Figure 1. The source code files that you would change in this project. You would change the app delegate and controller class source files directly. The user interface files are manipulated via Interface Builder.

Figure 1. The source code files that you would change in this project. You would change the app delegate and controller class source files directly. The user interface files are manipulated via Interface Builder.

main

The Objective-C file main.m contains the main method. This is where the program starts.

App Delegate

For this project (the program named FirstApp), the App Delegate class is created in the files FirstAppAppDelegate.h and FirstAppDelegate.m. This is where the application (from the Cocoa Touch perspective) starts and terminates. The start method is applicationDidFinishLaunching and the termination method is applicationWillTerminate (meaning, these are the methods where the developer can put the code that gets executed right after the launch and right before the termination). This class holds the window and the navigation controller at the top of the window.

View Controller

This application (FirstApp) has one view. The controller for that view is in the following files: RootViewController.h and RootViewController.m. The main view of this application is a table. Hence, this class is based on the table view controller (UITableViewController).

The Class Model Diagram

Following is the Class Model Diagram for the App Delegate and View Controller classes. You can generate this class model diagram by using the Design - Class Model menu item.

Figure 2. The Class Diagram for the iPhone application named FirstApp. Here the custom classes point towards built-in classes and a protocol. The application delegate implements UIApplicationDelegate protocol and the main view is based on UITableViewController.

Figure 2. The Class Diagram for the iPhone application named FirstApp. Here the custom classes point towards built-in classes and a protocol. The application delegate implements UIApplicationDelegate protocol and the main view is based on UITableViewController.

As you can see from the class diagram, there are two classes in this application: FirstAppAppDelegate and RootViewController.

The solid lines from these classes point to their base classes. FirstAppAppDelegate is derived from NSObject and RootViewController is derived from the class UITableViewController. The classes NSObject and UITableViewController are from the Cocoa Touch framework.

The dashed line from FirstAppAppDelegate points to UIApplicationDelegate, which is a protocol. This means, the FirstAppAppDelegate will implement some methods from the UIApplicationDelegate protocol. In this case, these two methods are applicationDidFinishLaunching and applicationWillTerminate.

Explanation for the Source Code

These individual source files and classes (main, application delegate, and the view controller) are explained in detail in the following articles:

Understanding a Typical main Method in Objective-C for iPhone Development

Application Delegate for the First iPhone Application Explained

View Controller for the First iPhone Application Explained

Take a Quick Quiz on this Article

1. Where does an iPhone application program actually start?



: xib is the interface file extension
Question 1 of 5
Article Series
Previous Article:
Test Your Knowledge: Debugging Fundamentals of an iPhone application explained
This article is part of the Series:
Article Series: Getting started with iPhone development
Next Article:
Test Your Knowledge: Source Code of First iPhone Application Explained
Bookmark and Share This

More Articles With Similar Tags
This is a test on the article that gives a quick overview of the development tools installed with iPhone SDK. These tools include Xcode, Interface Builder, Instruments, and iPhone Simulator. In the article, Dash Code, which is used to build web applications for iPhone is also introduced. GDB, the open source debugger, is discussed there as well.
icon-xcode-groups-files.jpg
This article discusses various parts of the Project window inside an Xcode project. It also gives a quick overview of the Groups and Files navigation window. The Run menu, the default toolbar, and the built-in source editor are also discussed.
This is a test on the article that discusses various parts of the Project window inside an Xcode project. It also gives a quick overview of the Groups and Files navigation window. The Run menu, the default toolbar, and the built-in source editor are also discussed.
icon-xcode-interface-builder-connection-panel.jpg
This article explains the user interface files of an iPhone application. Explains the contents of the .xib files, which store the user interface. Goes through the various windows (Document Window, User Interface Window, Inspector Window, Library Window, Connections Panel) of the Interface Builder. The example used is a simple navigation-based iPhone application.
This is a test on the article that explains the user interface files of an iPhone application. It explains the contents of the .xib files, which store the user interface. Goes through the various windows (Document Window, User Interface Window, Inspector Window, Library Window, Connections Panel) of the Interface Builder. The example used is a simple navigation-based iPhone application.
About  Contact  Privacy Policy  Site Map