What is objective-C? Objective-C is (OC ).
OC is a superset of C and fully compatible with C language. In addition to the features of C language, it also adds some new features, starting with @, such as @ interface and @ implementation.
@ Interface is used to define a subclass and can also be an API.
@intaerface Car : NSObject{ ShapeColor XXXX; ShapeRect XXXX; }
@ Implementation is used to define the class name. After defining the class name, you can use methods to redefine the parameter or name of the subclass, which is also the part of method implementation.
@implementation Car- (void) setFillColor : (ShapeColor)c{ fillColor = c; }//setFillColor
Method:
It is equivalent to the Function Definition in C, but it is different from the function definition.
The method has the method type (in '-' format), return value (Return Value 'void'), parameter type (INT, etc ). (PS: After the parameter type, you need to use a semicolon to Represent ':'. You can define a tag between the first parameter type and the second parameter type, or you can choose not to define it, according to your personal preferences .)
- (void) setFillColor: (ShapeColor) fillColor;
SELF: indicates the current class object or instance.
Self indicates the class itself, so you can directly [self class name]
Super: indicates the parent class object or instance of the current class.
+ Is used to reference the parent class.
-Is the object representing the parent class
Inheritance:
In C language, there are actually some headers similar to custom header files that can be used later, but the difference is different. in C language, you can customize and modify header files, but it cannot be modified on OC. nsobject is the ancestor of the vast majority on OC. Unless it is a special framework that you need to redefine, it will always inherit the features of nsobject.
@ Intaerface car: nsobject // car is the custom subclass, and nsobject is the parent class.
Inheritance has many advantages. Among them, it can reduce a lot of repeated content, thus reducing the time and effort that Programmers spend on modifying code.
Class and object:
A class is the abstraction of an object, and an object is a specific instance of a class. Classes are abstract and do not occupy memory, while objects are specific and occupy storage space. A class is a blueprint for creating objects. It is a software template that defines methods and variables included in a specific type of objects.
To be continued ....
Objective-C Lesson 1