很多做iOS的程序員都會(huì)遇到這樣一個(gè)很煩的問(wèn)題,Xcode在打印unicode的log的時(shí)候,會(huì)顯示videoURL = "/itcast/videos/11.C\U8bed\U8a00-\U6307\U9488\U4e0e\U5b57\U7b26\U4e32";類似于這種的蛋疼東西,根本看不出這是什么。
關(guān)于這種問(wèn)題的解決辦法就是給NSArray和NSDictionary加一個(gè)類別。
先創(chuàng)建NSArray+Log.h
里面代碼
#import <Foundation/Foundation.h>
@interface NSArray (Log)
@end
@interface NSDictionary (Log)
@end
然后創(chuàng)建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