将Xcode中控制台的Unicode转为中文

2017-03-14  本文已影响561人  践行者_Leng

废话不多说,直接看截图和上代码。

代码如下

在NSObject分类中的.h文件中的代码

#import <Foundation/Foundation.h>

@interfaceNSObject (ChangeUnicode)

+(NSString*)stringByReplaceUnicode:(NSString*)string;

@end

@interfaceNSArray (LengUnicode)

@end

@interfaceNSDictionary (LengUnicode)

@end

在NSObject分类中的.m文件中的代码

#import"NSObject+ChangeUnicode.h"

#import  <objc/runtime.h>  //导入运行时

@implementationNSObject (ChangeUnicode)

+(NSString*)stringByReplaceUnicode:(NSString*)string{

NSMutableString*convertedString=[stringmutableCopy];

[convertedStringreplaceOccurrencesOfString:@"\\U"withString:@"\\u"options:0range:NSMakeRange(0, convertedString.length)];

CFStringReftransform=CFSTR("Any-Hex/Java");

CFStringTransform((__bridgeCFMutableStringRef)convertedString,NULL, transform,YES);

returnconvertedString;

}

@end

@implementationNSArray (LengUnicode)

+ (void)load {

method_exchangeImplementations(class_getInstanceMethod([selfclass],@selector(description)),class_getInstanceMethod([selfclass],@selector(replaceDescription)));

method_exchangeImplementations(class_getInstanceMethod([selfclass],@selector(descriptionWithLocale:)),class_getInstanceMethod([selfclass],@selector(replaceDescriptionWithLocale:)));

method_exchangeImplementations(class_getInstanceMethod([selfclass],@selector(descriptionWithLocale:indent:)),class_getInstanceMethod([selfclass],@selector(replaceDescriptionWithLocale:indent:)));

}

- (NSString*)replaceDescription {

return[NSObjectstringByReplaceUnicode:[selfreplaceDescription]];

}

- (NSString*)replaceDescriptionWithLocale:(nullableid)locale {

return[NSObjectstringByReplaceUnicode:[selfreplaceDescriptionWithLocale:locale]];

}

- (NSString*)replaceDescriptionWithLocale:(nullableid)locale indent:(NSUInteger)level {

return[NSObjectstringByReplaceUnicode:[selfreplaceDescriptionWithLocale:localeindent:level]];

}

@end

@implementationNSDictionary (LengUnicode)

+ (void)load {

method_exchangeImplementations(class_getInstanceMethod([selfclass],@selector(description)),class_getInstanceMethod([selfclass],@selector(replaceDescription)));

method_exchangeImplementations(class_getInstanceMethod([selfclass],@selector(descriptionWithLocale:)),class_getInstanceMethod([selfclass],@selector(replaceDescriptionWithLocale:)));

method_exchangeImplementations(class_getInstanceMethod([selfclass],@selector(descriptionWithLocale:indent:)),class_getInstanceMethod([selfclass],@selector(replaceDescriptionWithLocale:indent:)));

}

- (NSString*)replaceDescription {

return[NSObjectstringByReplaceUnicode:[selfreplaceDescription]];

}

- (NSString*)replaceDescriptionWithLocale:(nullableid)locale {

return[NSObjectstringByReplaceUnicode:[selfreplaceDescriptionWithLocale:locale]];

}

- (NSString*)replaceDescriptionWithLocale:(nullableid)locale indent:(NSUInteger)level {

return[NSObjectstringByReplaceUnicode:[selfreplaceDescriptionWithLocale:localeindent:level]];

}

@end

最后不想copy的话,可以通过本人QQ:1205632644联系我,直接给源文件。

上一篇下一篇

猜你喜欢

热点阅读