1 The creation of the class:
@interface Car:nsobject
{
Variable name
}
Method declaration
@end
@implementation Car
Implementation of the method
@end
2 class Inheritance (OC does not support multiple inheritance, you can achieve multi-inheritance effects through other features, such as "category" Catergory and "Protocol" protocol)
@interface Circle:car
@end
2.1 "Post-inheritance method scheduling problem:
When the code sends the message, the calling method will first go inside itself to find out if there is no such method, if not it will go to his parent to find, know NSObject class inside. If not, an error will occur.
2.2 The problem of instance variables after inheritance:
An ISA instance variable is declared in the NSObject class, and a pointer to the current class is saved. So each class will have the class that the instance variable points to itself, so the instance variable that the subclass owns is its own instance variable plus the instance variable in the parent class and the ISA instance variable in the NSObject class.
2.3 "Inherited rewrite method problem:
overriding methods sometimes to change an instance variable declared in a parent class, you need to invoke the method in the parent class using the Super keyword.
3 "Compound relationship (that is, multiple classes are used in a class)
1 The description method is like the ToString () method in Java, and NSLog (@ "%@") calls the description method by default.
So to print an object can rewrite his description method
4 "Construction method
The method of constructing the class in OC is the Init method, overriding the Init method
-(ID) init
{
if (Slef =[super init])
{
、、、、、、
}
return self;
}
5 "Setter and getter method
The setter method is preceded by a set, and the Get method does not need to add a get, only the variable name is required.
Inheritance is a is-a relationship, and the compound is a has-a relationship.
"iOS Development" summary of classes in Objective-c