O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CLASSES

In Objective-C, you will spend a lot of time dealing with classes and objects. Hence, it is important to understand how classes are declared and defined in Objective-C.

@interface

To declare a class, you use the @interface compiler directive, like this:

@interface SomeClass : NSObject {

}

This is done in the header file (.h), and the class declaration contains no implementation. The preceding code declares a class named SomeClass, and this class inherits from the base class named NSObject.

image NOTE While you typically put your code declaration in an .h file, you can also put it inside an .m if need be. This is usually done for small projects.

image NOTE NSObject is the root class of most Objective-C classes. It defines the basic interface of a class and contains methods common to all classes that inherit from it. NSObject also provides the standard memory management and initialization framework used by most objects in Objective-C, as well as reflection and type operations.

In a typical View Controller class, the class inherits from the UlViewController class, such as in the following:

@interface HelloWorldViewController : UIViewController {

}

@implementation

To implement a class declared in the header file, you use the @implementation compiler directive, like this:

#import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required