关于Xcode无法打印出unicode的解决办法

很多做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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容