NSLog列印查年陣列字典物件的中文資訊

2021-09-19 04:05:59 字數 2051 閱讀 5856

使用nslog檢視資訊時,如果是nsarray、nsdictionary、nsobject的物件時,無法檢視到詳細的資訊,特別是中文時,無法正常顯示,這時候需要進行特殊設定。

1、對於nsarray、nsdictionary時,需要建立分類,並重寫方法- (nsstring *)descriptionwithlocale:(id)locale實現;

2、對於nsobject時,需要建立分類,重寫方法- (nsstring *)description實現。

實現**

#import ns_assume_nonnull_begin

@inte***ce nsarray (category)

@end

ns_assume_nonnull_end

#import "nsarray+category.h"

@implementation nsarray (category)

- (nsstring *)descriptionwithlocale:(id)locale indent:(nsuinteger)level

]; return str;

}@end

nsarray *array = @[@"張三", @"李四", @"wangwu", @"小明"];

nslog(@"array: %@", array);

2019-04-17 17:40:27.706032+0800 demolog[20566:576588] array: (

張三,李四,

wangwu,

小明,)

#import ns_assume_nonnull_begin

@inte***ce nsdictionary (category)

@end

ns_assume_nonnull_end

#import "nsdictionary+category.h"

@implementation nsdictionary (category)

- (nsstring *)descriptionwithlocale:(id)locale indent:(nsuinteger)level

]; return str;

}@end

nsdictionary *dict = @;

nslog(@"dict: %@", dict);

2019-04-17 17:40:27.706222+0800 demolog[20566:576588] dict:

#import ns_assume_nonnull_begin

@inte***ce nsobject (category)

@end

ns_assume_nonnull_end

#import "nsobject+category.h"

#import @implementation nsobject (category)

- (nsstring *)description

}free(properties);

return desc;

}@end

person *person = [[person alloc] init];

person.name = @"小明";

person.job = @"研發工程師";

person.age = @"28";

person.company = @"byd auto";

person.project = @[@"project1", @"王者榮耀", @"跑跑卡丁車", @"逃離神廟", @"吃雞"];

person.learn = @;

nslog(@"person: %@", person);

2019-04-17 17:40:27.706527+0800 demolog[20566:576588] person:

,}

列印陣列 shell陣列和字典

bash 裡面的陣列怎麼實現python中類似於字典的功能呢?bin bash echo shell定義字典 必須先宣告 declare a dic dic key1 value1 key2 value2 key3 value3 列印指定key的value echo 列印所有key值 echo 列印...

python 字典,元組,物件,陣列取值方法

def create self,cr,uid,vals,context none if context is none context if vals.get name vals name self.pool.get ir.sequence get cr,uid,sale.origin or ctx...

JS 陣列, 物件的增查改刪 多語法對比

建議 在用資料結構的時候,優先考慮map和set 考慮資料的唯一性 放棄傳統的陣列和object,特別是比較複雜的資料結構時 map與array的對比let map newmap let array map.set t 1 array.push console.info map array map,...