打印字典时,不调用- (NSString *)descriptionWithLocale:方法的解决

很多开发者,为了调试,都会写一个字典和数组的分类,用来打印数据.我也一样,但是升级了Xcode8之后,打印字典时,不再调用分类里

- (NSString *)descriptionWithLocale:

这个方法了,换了一个方法之后,又可以打印了,方法如下:

- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level

代码如下:
.h文件里面

#import <Foundation/Foundation.h>

@interface NSArray (CFLog)

@end

@interface NSDictionary (CFLog)


@end

.m文件如下:

#import "NSArray+CFLog.h"

@implementation NSArray (CFLog)

- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level{

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

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

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

    }];

    [nmString appendString:@"]\n"];

    return nmString.copy;
}
@end


@implementation NSDictionary (CFLog)

- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level{

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

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

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

    }];

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

    return nmString.copy;
}
@end

虽然现在也能打印了,但是不知作何解释,有没有小伙伴们可以给出答案

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值