• 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);
        }
    }
  • 相关阅读:
    Problem C: 时间类的常量
    Problem B: 时间类的错误数据处理
    Problem A: 时间类的拷贝和整体读写
    Problem B: 平面上的点——Point类 (IV)
    Problem C: 平面上的点——Point类 (V)
    Problem A: 平面上的点——Point类 (III)
    中间的数(若已经排好序)
    软件工程概论团队结组
    软件工程个人作业04 子数组循环数组
    软件工程个人作业03
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/9958827.html
Copyright © 2020-2023  润新知