First, description method
The description method includes class methods and object methods. (Included in the NSObject Class)
(i) Basic knowledge
-Description (Object method)
When you use NSLog and%@ to output an object, the object's description method is called and the return value is returned for output.
+ Description (class method)
When you use NSLog and%@ to output a class, the description method of the class is called, the return value is returned for output, the entire object is printed once, and the print object uses%@.
Use%@ to print objects such as ("%@", p) The default printout is the < class name: memory address, although the string is also an object, but the string is special when printing with%@.
So how do you implement all the properties of the printed object? Override the description method in the implementation of the class.
(ii) Implement all properties of the Print object
(c) Difference
The + Description method determines the output of the class object, which is the class itself
-The Description method determines the output of the instance object, which is the object created by the person.
(iv) Printing related supplements
Second, SEL
SEL: Full name selector represents the location where the method is stored.
How is the method stored in memory?
Person *p = [[Person alloc] init];
[P test];
The process of finding a method:
(1) First, the test method name is packaged into SEL type data;
(2) Find the corresponding method address according to the SEL data;
(3) Call the corresponding method according to the method address.
(4) Note: During this operation, there is a cache, the first time to find a time to find, very consumption performance, and then use the time when it is used directly.
About _cmd: There is a _cmd inside each method that represents the current method.
Note: The SEL is actually a wrapper for the method, wrapping the method into an SEL type of data, finding the corresponding method address, and then calling the method when the method address is found. These are run-time features, and the message is to send the SEL, and then find the address based on the SEL and invoke the method.
// manually wrapping the Eat method into the SEL type SEL S1 = @selector (eat); [P2 perfomselector:s1] was called through S1 ;
OC Language Description Method and SEL