首页 > 其他 > 详细

重写description方法

时间:2018-04-20 21:47:08      阅读:165      评论:0      收藏:0      [点我收藏+]

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

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

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

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

重写description方法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!