很多開發者,為了調試,都會寫一個字典和數組的分類,用來打印數據.我也一樣,但是升級了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雖然現在也能打印了,但是不知作何解釋,有沒有小伙伴們可以給出答案
新聞熱點
疑難解答