很多開發(fā)者,為了調(diào)試,都會(huì)寫一個(gè)字典和數(shù)組的分類,用來打印數(shù)據(jù).我也一樣,但是升級(jí)了Xcode8之后,打印字典時(shí),不再調(diào)用分類里
- (NSString *)descriptionWithLocale:
這個(gè)方法了,換了一個(gè)方法之后,又可以打印了,方法如下:
- (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雖然現(xiàn)在也能打印了,但是不知作何解釋,有沒有小伙伴們可以給出答案
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注