创建一个.m文件,然后将一下代码加入.m文件中即可实现控制台输出中文,具体代码如下:

#ifndef Release

@implementation NSSet(Log)

- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level 
{
NSMutableString *desc = [NSMutableString string];
NSMutableString *tabString = [[NSMutableString alloc] initWithCapacity:level];
for (NSUInteger i = ; i < level; ++i) {
[tabString appendString:@"\t"];
} NSString *tab = @"\t";
if (level > ) {
tab = tabString;
}
[desc appendString:@"\t{(\n"]; for (id obj in self) {
if ([obj isKindOfClass:[NSDictionary class]]
|| [obj isKindOfClass:[NSArray class]]
|| [obj isKindOfClass:[NSSet class]]) {
NSString *str = [((NSDictionary *)obj) descriptionWithLocale:locale indent:level + ];
[desc appendFormat:@"%@\t%@,\n", tab, str];
} else if ([obj isKindOfClass:[NSString class]]) {
[desc appendFormat:@"%@\t\"%@\",\n", tab, obj];
} else if ([obj isKindOfClass:[NSData class]]) {
// if is NSData,try parse
NSError *error = nil;
NSObject *result = [NSJSONSerialization JSONObjectWithData:obj
options:NSJSONReadingMutableContainers
error:&error]; if (error == nil && result != nil) {
if ([result isKindOfClass:[NSDictionary class]]
|| [result isKindOfClass:[NSArray class]]
|| [result isKindOfClass:[NSSet class]]) {
NSString *str = [((NSDictionary *)result) descriptionWithLocale:locale indent:level + ];
[desc appendFormat:@"%@\t%@,\n", tab, str];
} else if ([obj isKindOfClass:[NSString class]]) {
[desc appendFormat:@"%@\t\"%@\",\n", tab, result];
}
} else {
@try {
NSString *str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
if (str != nil) {
[desc appendFormat:@"%@\t\"%@\",\n", tab, str];
} else {
[desc appendFormat:@"%@\t%@,\n", tab, obj];
}
}
@catch (NSException *exception) {
[desc appendFormat:@"%@\t%@,\n", tab, obj];
}
}
} else {
[desc appendFormat:@"%@\t%@,\n", tab, obj];
}
} [desc appendFormat:@"%@)}", tab]; return desc;
} @end @implementation NSArray (Log) - (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level
{
NSMutableString *desc = [NSMutableString string];
NSMutableString *tabString = [[NSMutableString alloc] initWithCapacity:level];
for (NSUInteger i = ; i < level; ++i) {
[tabString appendString:@"\t"];
} NSString *tab = @"";
if (level > ) {
tab = tabString;
}
[desc appendString:@"\t(\n"]; for (id obj in self) {
if ([obj isKindOfClass:[NSDictionary class]]
|| [obj isKindOfClass:[NSArray class]]
|| [obj isKindOfClass:[NSSet class]]) {
NSString *str = [((NSDictionary *)obj) descriptionWithLocale:locale indent:level + ];
[desc appendFormat:@"%@\t%@,\n", tab, str];
} else if ([obj isKindOfClass:[NSString class]]) {
[desc appendFormat:@"%@\t\"%@\",\n", tab, obj];
} else if ([obj isKindOfClass:[NSData class]]) { NSError *error = nil;
NSObject *result = [NSJSONSerialization JSONObjectWithData:obj
options:NSJSONReadingMutableContainers
error:&error]; if (error == nil && result != nil) {
if ([result isKindOfClass:[NSDictionary class]]
|| [result isKindOfClass:[NSArray class]]
|| [result isKindOfClass:[NSSet class]]) {
NSString *str = [((NSDictionary *)result) descriptionWithLocale:locale indent:level + ];
[desc appendFormat:@"%@\t%@,\n", tab, str];
} else if ([obj isKindOfClass:[NSString class]]) {
[desc appendFormat:@"%@\t\"%@\",\n", tab, result];
}
} else {
@try {
NSString *str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
if (str != nil) {
[desc appendFormat:@"%@\t\"%@\",\n", tab, str];
} else {
[desc appendFormat:@"%@\t%@,\n", tab, obj];
}
}
@catch (NSException *exception) {
[desc appendFormat:@"%@\t%@,\n", tab, obj];
}
}
} else {
[desc appendFormat:@"%@\t%@,\n", tab, obj];
}
} [desc appendFormat:@"%@)", tab]; return desc;
} @end @implementation NSDictionary (Log) - (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level
{
NSMutableString *desc = [NSMutableString string];
NSMutableString *tabString = [[NSMutableString alloc] initWithCapacity:level];
for (NSUInteger i = ; i < level; ++i) {
[tabString appendString:@"\t"];
} NSString *tab = @"";
if (level > ) {
tab = tabString;
} [desc appendString:@"\t{\n"]; // Through array, self is array
for (id key in self.allKeys) {
id obj = [self objectForKey:key]; if ([obj isKindOfClass:[NSString class]]) {
[desc appendFormat:@"%@\t%@ = \"%@\",\n", tab, key, obj];
} else if ([obj isKindOfClass:[NSArray class]]
|| [obj isKindOfClass:[NSDictionary class]]
|| [obj isKindOfClass:[NSSet class]]) {
[desc appendFormat:@"%@\t%@ = %@,\n", tab, key, [obj descriptionWithLocale:locale indent:level + ]];
} else if ([obj isKindOfClass:[NSData class]]) { NSError *error = nil;
NSObject *result = [NSJSONSerialization JSONObjectWithData:obj
options:NSJSONReadingMutableContainers
error:&error]; if (error == nil && result != nil) {
if ([result isKindOfClass:[NSDictionary class]]
|| [result isKindOfClass:[NSArray class]]
|| [result isKindOfClass:[NSSet class]]) {
NSString *str = [((NSDictionary *)result) descriptionWithLocale:locale indent:level + ];
[desc appendFormat:@"%@\t%@ = %@,\n", tab, key, str];
} else if ([obj isKindOfClass:[NSString class]]) {
[desc appendFormat:@"%@\t%@ = \"%@\",\n", tab, key, result];
}
} else {
@try {
NSString *str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
if (str != nil) {
[desc appendFormat:@"%@\t%@ = \"%@\",\n", tab, key, str];
} else {
[desc appendFormat:@"%@\t%@ = %@,\n", tab, key, obj];
}
}
@catch (NSException *exception) {
[desc appendFormat:@"%@\t%@ = %@,\n", tab, key, obj];
}
}
} else {
[desc appendFormat:@"%@\t%@ = %@,\n", tab, key, obj];
}
} [desc appendFormat:@"%@}", tab]; return desc;
} @end #endif

以上代码实现了NSSet/NSDictionry/NSArray类型的展示。

最新文章

  1. GDB调试命令小结
  2. Django分析之使用redis缓存服务器
  3. unity gizmo绘制圆形帮助调试
  4. HighchartsJS创建环形带标识的图表实例
  5. JVM垃圾回收参数说明整理
  6. linux命令:mkdir
  7. HDU --- 4006
  8. 4种字符串匹配算法:KMP(下)
  9. linux内核笔记-内核同步
  10. 根据相同的字段创建或者修改一个Model
  11. iOS 之 内存管理
  12. Java语言程序设计基础篇第10版第5章习题答案
  13. 使用C#+XPath+HtmlAgilityPack轻松搞一个资源下载器
  14. chrome升级后出现滚动条无法滚动
  15. [C++]指针与引用(应用辨析)
  16. javascript中ajax的四大步骤
  17. 解决vshost32.exe已停止工作
  18. VSTO - 使用Excel加载项生成表和图表
  19. Office Web Apps 错误日志
  20. ios持久化存储

热门文章

  1. MATLAB学习笔记之界面基本操作
  2. How To : Modify ASM SYS password using asmcmd 11g R2 and upper
  3. hdu2008 数值统计【C++】
  4. Pyspider爬虫简单框架——链家网
  5. 《高性能MySQL》笔记-BLOB与TEXT
  6. VI 快捷操作 【持续更新】
  7. Colored Sticks (并查集+Trie + 欧拉路)
  8. c++实现数据结构1.顺序表
  9. Android Studio第一次启动的Fetching android sdk component information的问题
  10. Zepto Code Rush 2014-A. Feed with Candy(HACK)