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