關(guān)于Xcode無(wú)法打印出unicode的解決辦法

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容