美文网首页
利用分类解决字典、数组打印问题

利用分类解决字典、数组打印问题

作者: 豆汁儿还是豆花儿 | 来源:发表于2017-03-20 13:28 被阅读10次

    新建一个NSArray的分类

    .h文件

    #import <Foundation/Foundation.h>

    @interface NSArray (Log)

    @end

    @interface NSDictionary (Log)

    @end

    .m文件

    #import "NSArray+Log.h"

    @implementation NSArray (Log)

    - (NSString *)descriptionWithLocale:(id)locale

    {

    NSMutableString *strM = [NSMutableString stringWithString:@"(\n"];

    [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

    [strM appendFormat:@"\t%@,\n", obj];

    }];

    [strM appendString:@")"];

    return strM;

    }

    @end

    @implementation NSDictionary (Log)

    - (NSString *)descriptionWithLocale:(id)locale

    {

    NSMutableString *strM = [NSMutableString stringWithString:@"{\n"];

    [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

    [strM appendFormat:@"\t%@ = %@;\n", key, obj];

    }];

    [strM appendString:@"}\n"];

    return strM;

    }

    @end


    相关文章

      网友评论

          本文标题:利用分类解决字典、数组打印问题

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