解决 Xcode 输出台打印 NSArray 数组和 NSDictionary 字典中文乱码的问题
command+N 文件名随便
删除此分类的.h文件.将下列代码全部复制进.m.同时在.m文件导入#import <Foundation/Foundation.h>
@implementation NSArray (WJiaReDescFunction)//你的文件名
/**
解决数组输出中文乱码的问题
@return 输出结果
*/
- (NSString *)descriptionWithLocale:(id)locale {
NSMutableString *string = [NSMutableString stringWithString:@"(\n"];
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[string appendFormat:@"\t%@,\n", obj];
}];
if ([string hasSuffix:@",\n"]) {
[string deleteCharactersInRange:NSMakeRange(string.length - 2, 1)]; // 删除最后一个逗号
}
[string appendString:@")\n"];
return string;
}
@end
@implementation NSDictionary (WJiaReDescFunction)
/**
解决字典输出中文乱码的问题
@return 输出结果
*/
- (NSString *)descriptionWithLocale:(id)locale {
NSMutableString *string = [NSMutableString stringWithString:@"{\n"];
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[string appendFormat:@"\t%@ = %@;\n", key, obj];
}];
[string appendString:@"}\n"];
return string;
}
@end