关闭

解决NSArray和NSDictionary不支持中文的问题

145人阅读 评论(0) 收藏 举报
分类:

增加两个分类

#import "NSArray+Log.h"

@implementation NSArray (Log)

- (NSString *)descriptionWithLocale:(id)locale {
    NSMutableString *str = [NSMutableString string];
    
    [str appendString:@"[\n"];
    
    // 遍历数组所有元素
    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        [str appendFormat:@"%@, \n", obj];
    }];
    
    [str appendString:@"]"];
    
    return str;
}
@end

#import "NSDictionary+Log.h"

@implementation NSDictionary (Log)


/** 本地化显示 */
- (NSString *)descriptionWithLocale:(id)locale {
    NSMutableString *str = [NSMutableString string];
    
    [str appendString:@"{\n"];
    
    // 遍历字典
    [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        [str appendFormat:@"\t%@ = %@,\n", key, obj];
    }];
    
    [str appendString:@"}"];
    
    // 取出最后一个“,”
    NSRange range = [str rangeOfString:@"," options:NSBackwardsSearch];
    [str deleteCharactersInRange:range];
    
    return str;
}
@end


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22865次
    • 积分:1098
    • 等级:
    • 排名:千里之外
    • 原创:91篇
    • 转载:4篇
    • 译文:0篇
    • 评论:2条