问题描述
Xcode的Log日志输出中文的问题,一般都是重写NSArray,NSDictionary的- (NSString *)descriptionWithLocale:(id)locale;方法进行处理,最近升级到Xcode9会后发现原来的处理逻辑也无法满足输出中文的需求,后台返回的状态描述涉及到中文的都变成了Unicode编码,其实这是重写的方法失效的问题,因为Xcode默认输出NSArray,NSDictionary的中文都是Unicode编码
正确的解决方案如下,
创建NSArray+ZYLog分类
NSArray+ZYLog.h文件
//
// NSArray+ZYLog.h
// ZYLog
//
// Created by zhouyu on 17/11/08.
// Copyright © 2017年 zhouyu. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSArray (ZYLog)
@end
@interface NSDictionary (ZYLog)
@end
NSArray+ZYLog.m文件
//
// NSArray+ZYLog.m
// ZYLog
//
// Created by zhouyu on 17/11/08.
// Copyright © 2017年 zhouyu. All rights reserved.
//
#import "NSArray+ZYLog.h"
@implementation NSArray (ZYLog)
#ifdef DEBUG
- (NSString *)description {
return [self ZY_descriptionWithLevel:1];
}
-(NSString *)descriptionWithLocale:(id)locale{
return [self ZY_descriptionWithLevel:1];
}
- (NSString *)descriptionWithLocale:(nullable id)locale indent:(NSUInteger)level {
return [self ZY_descriptionWithLevel:(int)level];
}
/**
将数组转化成字符串,文字格式UTF8,并且格式化
@param level 当前数组的层级,最少为 1,代表最外层
@return 格式化的字符串
*/
- (