Description method [dead loop]

#import "MaTsonga .h"

@implementation MaTsonga

-(NSString *)description{
    return [NSString stringWithFormat:@"{name:%@,age:%i}",,self.age];


#import "MaTsonga .h"

int main(int argc, const char * argv[]) {

    MaTsonga *ma=[[MaTsonga alloc]init]; @"Is it like being silly";
    Nslog (@ "% @", MA); // the object description method will be called to return the corresponding description information
    return 0;

Note that the format character in nslog is% @. When% @ is used to output an object, objc will call the description of each object to return the corresponding information for output. By default, if we do not rewrite the description method, the output content is the class name and address.

It should be emphasized that do not print out self in the description, because when self is output, the description method of the object will be called, which will cause a dead loop.