General usefulness of the 1.description method
1: //address of the pointer variable
2: NSLog (@ "%p", &p);
3: //Address of Object
4: NSLog (@ "%p", p);
5: //< Class Name: Object address >
6: NSLog (@ "%@", p);
1: class];
2:
3: //1. The +description method that invokes the class
4: //2. Get the return value of the +description method (NSString *) displayed on the screen
5: NSLog (@ "%@", c);
Java-like ToString ()
2, the general use of description method attention points
1: //By default, when using NSLog and%@ output objects, the result is:< class name: Memory address >
2:
3: //1. The-description method that invokes the object P
4: //2. Get the return value of the-description method (NSString *) displayed on the screen
5: //The 3.-description method returns "class name + memory address" by default
6: NSLog (@ "%@", p);
7:
8: //person *p2 = [[Person alloc] init];
9: //nslog (@ "%@", p2);
10:
One : //nsstring *name = @ "Rose";
12:
: //nslog (@ "My name is%@", name);
14:
: person *p2 = [[Person alloc] init];
: p2.age = 25;
: @ "Jake";
18:
: NSLog (@ "%@", p2);
3. Usage of the Description method
1: //determines the output of the instance object
2: //-(NSString *) Description
3: //{
4: ////The following code will cause a dead loop
5: //// NSLog (@ "%@", self);
6: // return [NSString stringwithformat:@ "age=%d, name=%@", _age, _name];
7: // //return @ "3424324";
8: //}
9:
Ten: //determines the output of the class object
One : + (NSString *) description
: {
: return@ "ABC";
: }
Dark Horse programmer--"Dark Horse Video Notes" description method of OC Language Foundation