iPhone Development 101

iPhone 101

Code Tips

Resources

More

This tutorial was written for Xcode 3.2; it's outdated now. For a more up-to-date tutorial, check out Apple's App Development Tutorial to learn how to write iOS apps. There are also lots of other excellent books and online tutorials you can learn from.

If you'd like to find out when the updated version of this class is ready, follow me on twitter:

You won't be able to remember every method in every Cocoa class; there's just too much to remember. To be able to develop iPhone apps effectively, it's essential that you know how to find things in the documentation. You can open the documentation window by going to Xcode's Help menu and selecting Developer Documentation ( ⌘/ ). Notice the toolbar at the top of the window:

You can use the toolbar to search for a specific term or navigate to a particular documentation set. Select the "Home" button to see which documentation sets you have installed. You should see the latest iOS Library listed; if you don't, go back into Xcode Preferences ( ⌘ , ), select Documentation, and get it. (It may take a while to download the entire doc set.)

Once you've downloaded the doc sets, press the "Home" button in the toolbar and select the iOS Library. The library home page serves as a sort of table of contents for this documentation set. Documentation is categorized into different "resource types"; you'll be most interested in:

  • References - a class reference shows all of the properties and methods for that class, as well as any class-specific extras (delegates, notifications, etc.)
  • Guides - more in-depth explanations of a topic, along with example code.

You can also view the documentation on Apple's website at http://developer.apple.com/iphone/library/navigation/.

Getting Back to the Project

The documentation window is pretty big and may overlap your project window. To switch back, you can either close the documentation window, or go to Xcode's Window menu to navigate back to your project window.

You can also use the F10 key to launch Exposé, then use the arrow keys to navigate through Xcode's open windows.

Option-double-click to View the Research Assistant

If you option-double-click on a Cocoa symbol (such as a class or method name) in your code, the Research Assistant window will pop up. The assistant provides a quick look at documentation on a particular item without launching the full documentation window.

Try it: open the FirstAppDelegate.h file in your project, then option-double-click on the word UIWindow. The Research Assistant will pop up below the word you clicked:

If you click on the book icon in the research assistant, the full documentation window will open and take you to the class reference for that object.

Class References

Every Cocoa class has documentation in the form of a Reference page. The Reference has a table of contents frame on the left, and the documentation content frame on the right:

If the table of contents doesn't appear on the left, click the small arrow next to "Table of Contents". You can also click the arrows next to each section to show/hide the contents for that section.

Sections:

The Overview describes what this class does.

Tasks shows which properties and methods do particular tasks. (In the case of a protocol reference, the Tasks section should also show you which methods are optional or required.)

Properties are a special type of variable; they store a value (such as a number or string, or another object).

Methods are code that can be called to perform some action and/or return a value. (In other languages these might be called functions or subroutines, but in object-oriented languages like Objective-C, they're called methods.)

Class Methods (UIWindow has none) are called on the class itself:

[classname classMethod]; 

Instance Methods are methods that an instance of this class can call:

[myObject instanceMethod]; 

Constants are values that never change. These are often custom named values; for example, UIWindow defines a UIWindowLevel constant which can have one of three values: UIWindowLevelNormal, UIWindowLevelAlert, and UIWindowLevelStatusBar.

Notifications are messages the object sends in response to certain actions. Other classes in your project can listen for these notifications and react accordingly.

Inheritance

Cocoa is an object-oriented language. Every class inherits from another class, all the way back up to the root class (NSObject). You can view the inheritance of a class by clicking on the Overview link, then scrolling back up to the top of the contents frame. You'll see a box that looks like this:

This shows you that UIWindow inherits from UIView, which inherits from UIResponder, which inherits from NSObject. This means that UIWindow also has all of the properties on those objects, and responds to all of the methods on them. Click on the parent class links to view their documentation.

The info box also shows some other details about this class, including links to sample code and any related Guides.

A framework is a set of classes and code that relate to a common design pattern or idea. For example, the UIKit framework contains classes that handle user interface elements such as windows, views, buttons, text fields, etc. Click on the UIKit.framework link to see all of the classes in the framework. When you're done, use the back button at the top of the documentation window to navigate back to the UIWindow docs.

Now you should have a pretty good feel for navigating the documentation in Xcode. Next we'll look at creating your app's user interface with Interface Builder.

Additional References

TopHome