美文网首页
解决Xcode8控制台无法输出中文

解决Xcode8控制台无法输出中文

作者: 一个萝卜X个坑 | 来源:发表于2018-12-29 10:07 被阅读10次
    00001.png
    000002.png
    - (NSString *)descriptionWithLocale:(id)locale
    {
        NSMutableString *string = [NSMutableString string];
        
        // 开头有个{
        [string appendString:@"{\n"];
        
        // 遍历所有的键值对
        [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
            [string appendFormat:@"\t%@", key];
            [string appendString:@" : "];
            [string appendFormat:@"%@,\n", obj];
        }];
        
        // 结尾有个}
        [string appendString:@"}"];
        
        // 查找最后一个逗号
        NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
        if (range.location != NSNotFound)
            [string deleteCharactersInRange:range];
        
        return string;
    }
    @end
    
    @implementation NSArray (NSLog)
    
    - (NSString *)descriptionWithLocale:(id)locale
    {
        NSMutableString *string = [NSMutableString string];
        
        // 开头有个[
        [string appendString:@"[\n"];
        
        // 遍历所有的元素
        [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            [string appendFormat:@"\t%@,\n", obj];
        }];
        
        // 结尾有个]
        [string appendString:@"]"];
        
        // 查找最后一个逗号
        NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
        if (range.location != NSNotFound)
            [string deleteCharactersInRange:range];
        
        return string;
    }
    
    
    

    将这段代码放入.m中即可。

    相关文章

      网友评论

          本文标题:解决Xcode8控制台无法输出中文

          本文链接:https://www.haomeiwen.com/subject/bhkulqtx.html