首页 > 代码库 > 打印可读字典及数组
打印可读字典及数组
@implementation NSArray (Log) - (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level { NSMutableString *mStr = [NSMutableString string]; NSMutableString *tab = [NSMutableString stringWithString:@""]; for (int i = 0; i < level; i++) { [tab appendString:@"\t"]; } [mStr appendString:@"(\n"]; for (int i = 0; i < self.count; i++) { NSString *lastSymbol = (self.count == i + 1) ? @"":@","; id value =http://www.mamicode.com/ self[i]; if ([value respondsToSelector:@selector(descriptionWithLocale:indent:)]) { [mStr appendFormat:@"\t%@%@%@\n",tab,[value descriptionWithLocale:locale indent:level + 1],lastSymbol]; } else { [mStr appendFormat:@"\t%@%@%@\n",tab,value,lastSymbol]; } } [mStr appendFormat:@"%@)",tab]; return mStr; } @end @implementation NSDictionary (Log) - (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level { NSMutableString *mStr = [NSMutableString string]; NSMutableString *tab = [NSMutableString stringWithString:@""]; for (int i = 0; i < level; i++) { [tab appendString:@"\t"]; } [mStr appendString:@"{\n"]; NSArray *allKey = self.allKeys; for (int i = 0; i < allKey.count; i++) { id value =http://www.mamicode.com/ self[allKey[i]]; NSString *lastSymbol = (allKey.count == i + 1) ? @"":@";"; if ([value respondsToSelector:@selector(descriptionWithLocale:indent:)]) { [mStr appendFormat:@"\t%@%@ = %@%@\n",tab,allKey[i],[value descriptionWithLocale:locale indent:level + 1],lastSymbol]; } else { [mStr appendFormat:@"\t%@%@ = %@%@\n",tab,allKey[i],value,lastSymbol]; } } [mStr appendFormat:@"%@}",tab]; return mStr; } @end
打印可读字典及数组
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。