Description is a method that all classes have.
We override this method to customize the information for the instance output.
For example, we create a person class:
Add two properties to the. h file:
#import <Foundation/Foundation.h>@interface*int age ; @end
Override the description method in the. m file:
#import " Person.h " @implementation Person-(NSString *) description{ return [nsstring stringWithFormat:@ " <%p>-Name:%@, Age:%d", Self, _name, _age];} @end
Let's call it:
Person *person =@ "xiaoming"; NSLog (@ "person–%@", person);
The console will then output:
Person-<0x7fa20bc18d10
This is the custom output method in my description.
If we do not override the description method, the result of the console output is:
0x7fccd1e1c5f0>
To summarize:
That is, when we output all the properties of the class to the console, we can rewrite the description method so that we can observe the properties of the class at any time.
PS: When you do not override the description method, only the printed class name and the memory address of the class are displayed by default.
iOS override description method, custom console (log) information