zoukankan      html  css  js  c++  java
  • Xcode输出中文

    重写NSArray和NSDictionary分类Category就OK了!

    导入头文件

    #import <objc/runtime.h>
    + (void)load
    {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            zxf_swizzleSelector([self class], @selector(descriptionWithLocale:indent:), @selector(zxf_descriptionWithLocale:indent:));
        });
    }
    - (NSString *)zxf_descriptionWithLocale:(id)locale indent:(NSUInteger)level
    {
        return [self stringByReplaceUnicode:[self zxf_descriptionWithLocale:locale indent:level]];
    }
    - (NSString *)stringByReplaceUnicode:(NSString *)unicodeString
    {
        NSMutableString *convertedString = [unicodeString mutableCopy];
        [convertedString replaceOccurrencesOfString:@"\U" withString:@"\u" options:0 range:NSMakeRange(0, convertedString.length)];
        CFStringRef transform = CFSTR("Any-Hex/Java");
        CFStringTransform((__bridge CFMutableStringRef)convertedString, NULL, transform, YES);
        
        return convertedString;
    }
    static inline void zxf_swizzleSelector(Class theClass, SEL originalSelector, SEL swizzledSelector)
    {
        Method originalMethod = class_getInstanceMethod(theClass, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(theClass, swizzledSelector);
        
        BOOL didAddMethod =
        class_addMethod(theClass,
                        originalSelector,
                        method_getImplementation(swizzledMethod),
                        method_getTypeEncoding(swizzledMethod));
        
        if (didAddMethod) {
            class_replaceMethod(theClass,
                                swizzledSelector,
                                method_getImplementation(originalMethod),
                                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    }
  • 相关阅读:
    开发者论坛一周精粹(第九期)
    你刚吃的兰州牛肉面_背后就藏着大数据
    《C++覆辙录》——1.9:使用糟糕的语言
    老司机带你用MaxCompute和表格存储玩转车联网数据
    Gartner最新发布:2017年十大战略技术趋势
    js的事件的三个阶段,事件委托的原理
    Spring的AOP1
    了解SQL注入攻击
    了解XSS攻击
    了解Serialization
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/9958827.html
Copyright © 2011-2022 走看看