http://blog.cnrainbird.com/index.php/2012/07/19/object-c_zi_ding_yi_dui_xiang_nslog_shu_ru_you_yong_xin_xi/
NSLog(@"%@",_LocalVideo);
2012-07-19 09:37:46.933 umiwiForTest[2463:17803] <LocalVideo: 0x7cc3a9b0>
之前的时候有被同事问到这种情况怎么能输出这个对象的所有信息,我还一本正经的说自已写个循环挨个输出呗,哎,基础不牢害死人。今天自已遇到这个问题了。google一下,很快找到了答案:在自定义的类里实现- (NSString *)description;这个方法就可以了。
#pragma mark - description
- (NSString *)description{
return [NSString stringWithFormat:
@"{\n title = %@,\n subtitle = %@\n}",
self.title,self.subTitle];
}
2012-07-19 10:07:13.326 umiwiForTest[2951:17803] {
title = 邓峰:双向交流做好了,才能提高执行力,
subtitle = 时长: 00:02:35 点播: 4163日期: 2010-05-07 17:18:00
}
2012-07-19 10:06:22.595 umiwiForTest[2927:17803] (
"{\n title = \U9093\U5cf0\Uff1a\U53cc\U5411\U4ea4\U6d41\U505a\U597d\U4e86\Uff0c\U624d\U80fd\U63d0\U9ad8\U6267\U884c\U529b,\n subtitle = \U65f6\U957f: 00:02:35 \U70b9\U64ad: 4163\U65e5\U671f: 2010-05-07 17:18:00\n}",
"{\n title = \U674e\U5f00\U590d\Uff1a\U79fb\U52a8\U4e92\U8054\U7f51\U5728\U519c\U6751\U7684\U53d1\U5c55,\n subtitle = \U65f6\U957f: 00:02:14 \U70b9\U64ad: 12064\U65e5\U671f: 2010-04-16 12:42:00\n}",
"{\n title = \U674e\U5f00\U590d\Uff1a\U79fb\U52a8\U4e92\U8054\U7f51\U5728\U519c\U6751\U7684\U53d1\U5c55,\n subtitle = \U65f6\U957f: 00:02:14 \U70b9\U64ad: 12064\U65e5\U671f: 2010-04-16 12:42:00\n}",
"{\n title = \U674e\U5f00\U590d\Uff1a\U79fb\U52a8\U4e92\U8054\U7f51\U5728\U519c\U6751\U7684\U53d1\U5c55,\n subtitle = \U65f6\U957f: 00:02:14 \U70b9\U64ad: 12064\U65e5\U671f: 2010-04-16 12:42:00\n}",
"{\n title = \U674e\U5f00\U590d\Uff1a\U79fb\U52a8\U4e92\U8054\U7f51\U5728\U519c\U6751\U7684\U53d1\U5c55,\n subtitle = \U65f6\U957f: 00:02:14 \U70b9\U64ad: 12064\U65e5\U671f: 2010-04-16 12:42:00\n}"
)
#1: Interestingly, if I make my class a subclass of NSArray then NSDictionary calls descriptionWithLocale:indent: and it formats correctly. Sounds like NSDictionary is "cheating" and testing isKindOfClass rather than respondsToSelector, or else is just prejudiced against non-NS stuff.
It‘s kind of ugly to have to subclass NSArray, though, in terms of acquiring a lot of behaviors I don‘t want to mimic, and carrying extra unused data. Etc
#2: Another option is to convert the escaped string back to its original. This takes a 31-line procedure to handle the basics (\n, \t, \", and \). The up-side is that I don‘t need to subclass NSArray. The main downside is that this routine must be inserted in any NSLog call that could display my class. Another minor downside is that the escaped strings were wrappered with quote characters I can‘t eliminate, but that‘s hardly noticeable.
上面说,要么重新NSArray重新实现description,要么去掉这些特殊字符的转义。想想为了输全一个自已写的类要重新NSArray有点大题小作,而去掉这些特殊字符的转义也不是我想要的,因为我就是格式化出来,方便查看嘛,罢了,罢了,看来是无解,就此搁下。