Saturday, 24 November 2012

Classes

In Objective-C, you define objects by defining their class. The class definition is a prototype for a kind of object; it declares the instance variables that become part of every member of the class, and it defines a set of methods that all objects in the class can use. All instances of a class have access to the same set of methods, and they all have a set of instance variables cut from the same mold. Each object gets its own instance variables, but the methods are shared.

Class Names in Source Code

In source code, class names can be used in only two very different contexts. These contexts reflect the dual role of a class as a data type and as an object:
1. The class name can be used as a type name for a kind of object. For example:

Rectangle *anObject;
anObject = [[Rectangle alloc] init];

2. In any other context, you must ask the class object to reveal its id (by sending it a class message). The example below passes the Rectangle class as an argument in an isKindOf: message.

if ([anObject isKindOf:[Rectangle class]])

0 comments:

 
© Copyright 2035 iOS Developer
Theme by Yusuf Fikri