码迷,mamicode.com
首页 > 其他好文 > 详细

NSDictionary NSArray 转中文输出

时间:2016-05-10 12:27:58      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

//
//  NSDictionary+DescribetionDictionary.m
//  fengzi
//
//  Created by 谢泽锋 on 16/5/10.
//  Copyright © 2016年 xiezefeng. All rights reserved.
//

#import <Foundation/Foundation.h>
//数据字典数字打印中文显示

@implementation NSDictionary (DescribetionDictionary)
-(NSString *)descriptionWithLocale:(id)locale{

    NSMutableString * string=[NSMutableString string];
    //开头有个[
    [string appendString:@"{\n"];
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull 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(Log)

-(NSString *)descriptionWithLocale:(id)locale{
    
    NSMutableString * string=[NSMutableString string];
    //开头有个[
    [string appendString:@"[\n"];
    [self enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [string appendFormat:@"\t%@,\n",obj];
        
    }];
    //结尾有个]
    [string appendString:@"]"];
    //查找最后一个逗号
    NSRange range=[string rangeOfString:@"," options:NSBackwardsSearch];//从后往前找
    if (range.location !=NSNotFound) {
        [string deleteCharactersInRange:range];
    }
    return string;
    
}

@end


NSDictionary NSArray 转中文输出

标签:

原文地址:http://www.cnblogs.com/xiezefeng/p/5477108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!