1. 程式人生 > >解決iOS 打印出來的漢字為UTF8 格式

解決iOS 打印出來的漢字為UTF8 格式

陣列 和字典打印出來的漢字 一直是UTF8編碼, 看資料不方便

只需要給 NSArray 和NSDictionary 新增兩個分類 就能解決了此問題

#import "NSArray+decription.h"

@implementation NSArray (decription)

- (NSString *)descriptionWithLocale:(id)locale

{

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

    for

(id obj in self) {

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

    }

    [str appendString:@")"];

    return str;

}

@end

#import "NSDictionary+decription.h"

@implementation NSDictionary (decription)

- (NSString *)descriptionWithLocale:(id)locale

{

    NSArray *allKeys = [self allKeys

];

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

    for (NSString *key in allKeys) {

        id value= self[key];

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

    }

    [str appendString:@"}"];

    return str;

}

@end