码迷,mamicode.com
首页 > 其他好文 > 详细

重写description方法

时间:2018-04-20 22:07:08      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:script   年龄   with   重写   mat   div   方法   nsstring   pre   

重写description方法,当使用%@时就会输出特定的字符串。

- (NSString *)description {
  return [NSString stringWithFormat:@"姓名:%@, 年龄:%d", _name, _age];
}

 Person *person = [[Person alloc] init];

之后在使用NSLog(@"%@", person)时,就使用的是description方法。

重写description方法

标签:script   年龄   with   重写   mat   div   方法   nsstring   pre   

原文地址:https://www.cnblogs.com/cchHers/p/8893565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!