OC-description方法重写

description方法的作用是打印对象
对于一个Person类,如果没有重写description方法,NSLog(@“%@”,p),输出的是对象的内存地址,而我们想要的效果是打印出Person的成员变量,所以我们可以在Person类里重写description方法。

description方法,返回值是OC字符串

- (NSString *)description
{
   return    [NSString stringWithFormat:@”name is%@”,_name];
}

 

posted on 2015-08-11 15:56  Marshall_Yin  阅读(323)  评论(0编辑  收藏  举报