Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Objects form the heart of object-oriented programming. You define objects by building classes, which act as object creation templates. In Objective-C, a class definition specifies how to build new objects that belong to the class. So to create a “widget” object, you define the Widget class and then use that class to create new objects on demand.
Each class lists its instance variables and methods in a public header file using the standard C .h convention. For example, you might define a Car object like the one shown in Listing 2-1. The Car.h header file shown here contains the interface that declares how a Car object is structured.
Listing 2-1. Declaring the Car Interface (Car.h)
#import <Foundation/Foundation.h>
@interface Car : NSObject
{
int year;
NSString *make;
NSString *model;
}
- (void) setMake:(NSString *) aMake andModel:(NSString *) aModel
andYear: (int) aYear;
- (void) printCarInfo;
- (int) year;
@end