Class / instance attributes
Classes are similar to house type drawings. Instances are like real houses. Thus, you can only have one project for one type of house, but you can have several real houses of the same type. In addition, you can have several drawings, and each drawing describes a different type of house.
Another analogy you can use is that classes are like cookie cutters, and instances are like cookies made from a cookie cutter.
How does this relate to Objective-C
There is one “class object” for each class of your code. To refer to a class object, you simply use the class name. - a class method that allocates a new instance as follows: alloc
MyWidget* w = [MyWidget alloc];
alloc , - . init - , . , , :
MyWidget* w = [[MyWidget alloc] init];
:
MyWidget* w = [MyWidget alloc]; //alloc is being called on the class
w = [w init]; //init is being called on the instance
factory, numberWithChar:. , numberWithChar: :
+(NSNumber*) numberWithChar:(char)c;
{
return [[[NSNumber alloc] initWithChar:c] autorelease];
}
, numberWithChar: .
. .