NSDictionary+Log.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // NSDictionary+Log.m
  3. // VclustersGemini
  4. //
  5. // Created by xd h on 2020/6/24.
  6. // Copyright © 2020 APPLE. All rights reserved.
  7. //
  8. #import "NSDictionary+Log.h"
  9. @implementation NSDictionary (Log)
  10. - (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level
  11. {
  12. NSMutableString *mStr = [NSMutableString string];
  13. NSMutableString *tab = [NSMutableString stringWithString:@""];
  14. for (int i = 0; i < level; i++) {
  15. [tab appendString:@"\t"];
  16. }
  17. [mStr appendString:@"{\n"];
  18. NSArray *allKey = self.allKeys;
  19. for (int i = 0; i < allKey.count; i++) {
  20. id value = self[allKey[i]];
  21. NSString *lastSymbol = (allKey.count == i + 1) ? @"":@";";
  22. if ([value respondsToSelector:@selector(descriptionWithLocale:indent:)]) {
  23. [mStr appendFormat:@"\t%@%@ = %@%@\n",tab,allKey[i],[value descriptionWithLocale:locale indent:level + 1],lastSymbol];
  24. } else {
  25. [mStr appendFormat:@"\t%@%@ = %@%@\n",tab,allKey[i],value,lastSymbol];
  26. }
  27. }
  28. [mStr appendFormat:@"%@}",tab];
  29. return mStr;
  30. }
  31. @end