In iOS development, which often need to see if the array elements have to be what you want, but Apple did not make a direct deal with the array have Chinese printing, direct printing will be a bunch of very nasty things, to solve it is actually very simple, is the need to add a category for NSArray, rewrite - (NSString *) descriptionWithLocale: (id) locale method to
code show as below:
#import "NSArray+Log.h" @implementation NSArray (Log) - (NSString *)descriptionWithLocale:(id)locale { NSMutableString *str = [NSMutableString stringWithFormat:@"%lu (\n", (unsigned long)self.count]; for (id obj in self) { [str appendFormat:@"\t%@, \n", obj]; } [str appendString:@")"]; return str; } @end
Similarly NSDictionary to solve the garbage problem, also you need to add a NSDictionary class classification, rewrite - (NSString *) descriptionWithLocale: (id) locale method
code show as below:
1 #import "NSDictionary+MyLog.h" 2 3 @implementation NSDictionary (MyLog) 4 5 6 - (NSString *)descriptionWithLocale:(id)locale 7 { 8 NSArray *allKeys = [self allKeys]; 9 NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"{\t\n "]; 10 for (NSString *key in allKeys) { 11 id value= self[key]; 12 [str appendFormat:@"\t \"%@\" = %@,\n",key, value]; 13 } 14 [str appendString:@"}"]; 15 16 return str; 17 } 18 @end
Reproduced in: https: //www.cnblogs.com/pretty-guy/p/4054924.html