NSDictionary *dictionary = @{@"A" : @"alfa",
@"B" : @"bravo",
@"C" : @"charlie",
@"D" : @"delta",
@"E" : @"echo",
@"F" : @"foxtrot"};
NSLog(@"%@", dictionary.description);
打印出的控制檯上執行以下操作:有沒有辦法將Swift字典漂亮地打印到控制檯?
{
A = alfa;
B = bravo;
C = charlie;
D = delta;
E = echo;
F = foxtrot;
}
let dictionary: [String : String] = ["A" : "alfa",
"B" : "bravo",
"C" : "charlie",
"D" : "delta",
"E" : "echo",
"F" : "foxtrot"];
print(dictionary)
打印出的控制檯上執行以下操作:
["B": "bravo", "A": "alfa", "F": "foxtrot", "C": "charlie", "D": "delta", "E": "echo"]
是否有斯威夫特的方式來得到它漂亮的打印字典,其中每個鍵 - 值對佔據一個新的行?
,你可以例如,如果目標是檢查字典,則使用'dump'。 http://stackoverflow.com/documentation/swift/3966/logging-in-swift/14168/dump – Moritz
'print(dictionary as!NSDictionary)'cheap trick? – BaseZen
我真的是轉儲()的建議,因爲它不需要寫任何代碼或轉換它。 @EricAya,如果你發表了這個評論的答案,我會將其標記爲答案。 –