NSLog 日志打印出中文
1 - NSLog日志可以正常打印出中文,而不被编译成其它字符,对字典进行扩展即可
2 - 代码示例
// - NSDictionary+Log.m
1 #import "NSDictionary+Log.h" 2 @implementation NSDictionary (Log) 3 - (NSString *)descriptionWithLocale:(id)locale { 4 5 NSMutableString *string = [NSMutableString string]; 6 7 // 开头有个{ 8 [string appendString:@"{\n"]; 9 10 // 遍历所有的键值对 11 [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 12 [string appendFormat:@"\t%@", key]; 13 [string appendString:@" : "]; 14 [string appendFormat:@"%@,\n", obj]; 15 }]; 16 17 // 结尾有个} 18 [string appendString:@"}"]; 19 20 // 查找最后一个逗号 21 NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch]; 22 if (range.location != NSNotFound) 23 [string deleteCharactersInRange:range]; 24 25 return string; 26 } 27 @end 28 29 @implementation NSArray (Log) 30 31 - (NSString *)descriptionWithLocale:(id)locale 32 { 33 NSMutableString *string = [NSMutableString string]; 34 35 // 开头有个[ 36 [string appendString:@"[\n"]; 37 38 // 遍历所有的元素 39 [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 40 [string appendFormat:@"\t%@,\n", obj]; 41 }]; 42 43 // 结尾有个] 44 [string appendString:@"]"]; 45 46 // 查找最后一个逗号 47 NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch]; 48 if (range.location != NSNotFound) 49 [string deleteCharactersInRange:range]; 50 51 return string; 52 } 53 54 @end