Dark Horse Programmer--dot syntax, description, SEL, ID use
------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
Introduction and use of point syntax
**p.age;**
Object. Property name
Note: At this point, the (object. property name) does not directly access the instance variable. Instead of seeing the dot syntax, we automatically replace the p.age=18-replacement with [P setage:18];
*************************
int a=p.age;//Call Get method
Note: When you see P.age appearing on the right side of the equal sign, it is automatically replaced with p.age--replacement-->[p age];
Emphasis: Whether P.age is replaced with a get or set method, usually depends on whether P.age appears on the left or right side of the equals sign (whether it is a set value or a value assignment)
Dead Loop:
Set Method:
-(void) Setage: (int) NewAge {
The following code will cause a dead loop
Self.age = NewAge;
}
Equivalent
-(void) Setage: (int) NewAge {
[Self setage:newage];
}
Dead Loop:
In the Get method, return self.age is equivalent to [self-age];
********************************
Description Method Introduction and rewriting
When the object or class is printed in%@ format, the object's description method is called. Object, if the parent class's description method is not overridden, the parent class is called
********************************
Where the SEL method is stored
Is the packaging of the method, packaged into SEL type data
Find the corresponding method address based on the SEL data
Call the appropriate method based on the method address
Example: Wrapping the test method into an SEL type
SEL S1 = @selector (test);
Use:
[P performselector:test];
*********************************
Coercion Type Conversion Example:
NSObject *obj=[animal New];
[(animal*) obj run];
[(Subclass name *) pointer name behavior]
*********************************
ID using:
There is no need to enforce type conversions, which can be used directly, as is the dynamic type that the compiler checks for types.
ID obj;
Obj=dog;
[obj Run]
Equivalent to NSObject *
Instancetype and ID
Same: Can be used as the return type of a method
Different:
Instancetype can return objects of the same type as the method. ID can only return objects of unknown type
Instancetype can be used only as a return value, and an ID is also available as a parameter
------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------
Dark Horse Programmer--dot syntax, description, SEL, ID use