解决iOS 打印出来的汉字为UTF8 格式

时间:2023-01-10 11:14:59

数组 和字典打印出来的汉字 一直是UTF8编码, 看数据不方便

只需要给 NSArray 和NSDictionary 添加两个分类 就能解决了此问题


#import "NSArray+decription.h"


@implementation NSArray (decription)


- (NSString *)descriptionWithLocale:(id)locale

{

    NSMutableString *str = [NSMutableStringstringWithFormat:@"%lu (\n", (unsignedlong)self.count];

    

    for (id objin self) {

        [str appendFormat:@"\t%@, \n", obj];

    }

    

    [str appendString:@")"];

    

    return str;

}

@end



#import "NSDictionary+decription.h"


@implementation NSDictionary (decription)

- (NSString *)descriptionWithLocale:(id)locale

{

    NSArray *allKeys = [selfallKeys];

    NSMutableString *str = [[NSMutableStringalloc] initWithFormat:@"{\t\n "];

    for (NSString *keyin allKeys) {

        id value= self[key];

        [str appendFormat:@"\t \"%@\" = %@,\n",key, value];

    }

    [str appendString:@"}"];

    

    return str;

}

@end

解决iOS 打印出来的汉字为UTF8 格式解决iOS 打印出来的汉字为UTF8 格式解决iOS 打印出来的汉字为UTF8 格式