1) The class definition of objective-c contains two parts, one is the declaration of the class interface, and the other is the implementation of the class method.
2) All compilation instructions for all objective-c are preceded by @.
A) The class interface begins with @interface and ends with @end.
b) The implementation of the class begins with @implementation and ends with @end.
c) Each implementation file must contain its own corresponding interface file, so that the implementation file can be safe to delete the parent class name, the class's instance variable declaration is deleted, only the implementation of the method of the class; This can be done because there is no need to repeat the same declaration in the interface file.
d) Do not name the function parameter in the source file as a variable with the same name as the class member variable, otherwise the parameter name of the function overrides the member variable of the class, causing the member variable in the class definition to be invisible in the implementation of the function.
As in the header file, a class interface declaration is as follows:
@interface Circle:nsobject
{
Shaperect bounds;
Shapecolor FillColor;
}
-(void) Setfillcolor: (Shapecolor) FillColor;
-(void) SetBounds: (shaperect) bounds;
-(void) draw;
@end//circle
The implementation of the classes in our source files is as follows:
@implementation Circle
-(void) Setfillcolor: (Shapecolor) C
{
FillColor = C;
}
-(void) SetBounds: (shaperect) b
{
bounds = b;
}
-(void) Draw
{
NSLog (@ "Drawing a circle at (%d,%d,%d,%d) in%@", Bounds.x,bounds.y,bounds.width,bounds.hight,colorname (FillColor));
}
@end//circle
3) ID is unique, in objective-c it is a generic type of variable that can store pointers to any one object.
4) Send a message to an object, then how does the object execute the code corresponding to the message?
Each object contains a pointer to its class, and the class contains a pointer to the code area of the class.
When the object receives a message, the object finds its owning class object through its contained pointer, and the code area pointer of the class object can then find the function corresponding to the message.
Each object contains a pointer called Isa, which is the pointer to the class.
5) Basic terminology in OBJECTIVE-C:
class : A class is a structure that is used to represent the type of an object. The object uses the ISA pointer to refer to the class to get all the information about itself, especially the code for each operation, as described in 4.
Object: It is also a structure that mainly contains the value of the member variable and the hidden pointer to its class (ISA), and all of the same class share a piece of code.
Example: is another salutation to "object".
Message: Is an action that an object can perform to inform the object what to do, and an object can respond to which messages can be known from the interface definition.
Method: Code that runs in response to a message. Depending on the class of the object, the message can call different methods.
interface : is a description of the attributes that the class of the object should provide. The equivalent is to tell other customers who are using the class which messages the object of the class can receive. Consistent with the term "message" above.
implementation : Is the code that makes the interface work correctly, that is, the code that makes the object message work correctly. Consistent with the "implementation" term above.
6) Some methods have a colon after the name, some do not? How do you tell when there is, when not?
A colon is required if the method uses parameters, otherwise no colon is required. As in the code snippet above.
iOS development-objective-c Object-oriented Programming basics