首页 > 学院 > 开发设计 > 正文

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

2019-11-09 16:14:58
字体:
来源:转载
供稿:网友

很多开发者,为了调试,都会写一个字典和数组的分类,用来打印数据.我也一样,但是升级了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

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表