• ios nslog 打印字典为中文


    #import <Foundation/Foundation.h>
    
    @implementation NSDictionary (Log)
    - (NSString *)descriptionWithLocale:(id)locale
    {
        NSMutableString *str = [NSMutableString string];
        
        [str appendString:@"{
    "];
        
        // 遍历字典的所有键值对
        [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
            [str appendFormat:@"	%@ = %@,
    ", key, obj];
        }];
        
        [str appendString:@"}"];
        
        // 查出最后一个,的范围
        NSRange range = [str rangeOfString:@"," options:NSBackwardsSearch];
        if (range.length != 0) {
            // 删掉最后一个,
            [str deleteCharactersInRange:range];
        }
        
        return str;
    }
    @end
    
    @implementation NSArray (Log)
    - (NSString *)descriptionWithLocale:(id)locale
    {
        NSMutableString *str = [NSMutableString string];
        
        [str appendString:@"[
    "];
        
        // 遍历数组的所有元素
        [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            [str appendFormat:@"%@,
    ", obj];
        }];
        
        [str appendString:@"]"];
        
        // 查出最后一个,的范围
        NSRange range = [str rangeOfString:@"," options:NSBackwardsSearch];
        if (range.length != 0) {
            // 删掉最后一个,
            [str deleteCharactersInRange:range];
        }
        
        return str;
    }
    @end
    

      

  • 相关阅读:
    idea database testconnection 显示灰色
    idea tomcat热部署
    idea 常见报错问题 记录
    Python-Basis-22th
    Python-Basis-21th
    Python-Basis-20th
    Python-Basis-19th
    Python-Basis-18th
    Python-Basis-17th
    Python-Basis-16th
  • 原文地址:https://www.cnblogs.com/athook/p/4846315.html
Copyright © 2020-2023  润新知