NSLog印刷テクニック
1336 ワード
#import "NSArray+Log.h"
@implementation NSArray (Log)
// NSArray
- (NSString *)descriptionWithLocale:(id)locale{
NSMutableString *strM = [NSMutableString stringWithString:@"(
"];
//
[self enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[strM appendFormat:@"\t%@,
",obj];
}];
[strM appendFormat:@")
"];
return strM;
}
@end
@implementation NSDictionary (Log)
- (NSString *)descriptionWithLocale:(id)locale{
NSMutableString *strM = [NSMutableString stringWithString:@"(
"];
//
[self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
// \t
[strM appendFormat:@"\t%@ = %@,
",key, obj];
}];
[strM appendFormat:@")
"];
return strM;
}
@end
+ (instancetype)personWithDict:(NSDictionary *)dict{
id obj = [[self alloc] init];
[obj setValuesForKeysWithDictionary:dict];
return obj;
}
- (NSString *)description{
return [NSString stringWithFormat:@"{name:%@,age:%@}",[self class],self,self.name,self.age];
}
@end