很多做iOS的程序员都会遇到这样一个很烦的问题,Xcode在打印unicode的log的时候,会显示videoURL = "/itcast/videos/11.C\U8bed\U8a00-\U6307\U9488\U4e0e\U5b57\U7b26\U4e32";类似于这种的蛋疼东西,根本看不出这是什么。
关于这种问题的解决办法就是给NSArray和NSDictionary加一个类别。
先创建NSArray+Log.h
里面代码
#import <Foundation/Foundation.h>
@interface NSArray (Log)
@end
@interface NSDictionary (Log)
@end
然后创建NSArray+Log.m
里面代码
#import "NSArray+Log.h"
@implementation NSArray (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *strM = [NSMutableString stringWithString:@"(\n"];
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[strM appendFormat:@"\t%@,\n", obj];
}];
[strM appendString:@")"];
return strM;
}
@end
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *strM = [NSMutableString stringWithString:@"{\n"];
[self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[strM appendFormat:@"\t%@ = %@;\n", key, obj];
}];
[strM appendString:@"}\n"];
return strM;
}
@end
网友评论