很多开发者,为了调试,都会写一个字典和数组的分类,用来打印数据.我也一样,但是升级了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虽然现在也能打印了,但是不知作何解释,有没有小伙伴们可以给出答案
新闻热点
疑难解答