原理
步骤
- 创建一个
Foundation+Log.m
文件
- 在.m问价实现代码
#import <Foundation/Foundation.h>
@implementation NSDictionary (Log)
-(NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *string = [NSMutableString string];
[string appendString:@"{\n"];
[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
[string appendFormat:@"%@:",key];
[string appendFormat:@"%@,\n",obj];
}];
[string appendString:@"}"];
NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
if (range.location != NSNotFound) {
[string deleteCharactersInRange:range];
}
return string;
}
@end
@implementation NSArray (Log)
-(NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *string = [NSMutableString string];
[string appendString:@"["];
[self enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[string appendFormat:@"%@,",obj];
}];
[string appendString:@"]"];
NSRange range = [string rangeOfString:@"," options:NSBackwardsSearch];
if (range.location != NSNotFound) {
[string deleteCharactersInRange:range];
}
return string;
}
@end